Coder Social home page Coder Social logo

goaddr's Introduction

goaddr

A Restful API (and db) for a super simple Address Book written in Golang. Requires Go 1.16 or higher to be installed.

The following commands will download the executable into your go files and run the API server on port 8080:

go get github.com/deversmann/goaddr
goaddr

The server will generate the db file the first time in the directory where you execute the command. Subsequent executions in the same directory will reuse the same db file

API Definition

Call Success Failure
POST /api/v1/contacts/ 201 created 400 if JSON is not valid
GET /api/v1/contacts/ 200 OK 404 if no contacts are found
GET /api/v1/contacts/:id 200 OK 404 if contact with id is not found
PUT /api/v1/contacts/:id 202 accepted 400 if JSON is not valid
404 if contact with id is not found
DELETE /api/v1/contacts/:id 204 no content 404 if contact with id is not found

If an entry is retrieved, created or modified, the api will return a JSON representation of that entry:

{
    "id": 1,
    "firstname": "Paul",
    "lastname": "Cormir",
    "address": "100 E. Davie St.",
    "city": "Raleigh",
    "state": "NC",
    "zipcode": "27601",
    "phone": "888-RED-HAT-1",
    "email": "[email protected]"
}

If a collection is requested, the entries are returned in a JSON list:

{
  "contacts": [
    {
      "id": 1,
      "firstname": "Paul",
      "lastname": "Cormir",
      "address": "100 E. Davie St.",
      "city": "Raleigh",
      "state": "NC",
      "zipcode": "27601",
      "phone": "888-RED-HAT-1",
      "email": "[email protected]"
    },
    ...
  ]
}

If an error occurs, the HTTP error code will be accompanied by a message describing the failure:

{
  "message": "Invalid JSON for contact",
  "status": 400
}

goaddr's People

Contributors

deversmann avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.