Code Monkey home page Code Monkey logo

api's Introduction

Go API

A simple REST API with CRUD operations. The API will use an internal array, built and run on go version go1.12 but will probably work fine on earlier versions as well.

https://golang.org/

How to build it

To build the api from source - you need to install go, pull the dependancies and compile.

Pull the dependancies based on the dependancy list in the repo.

user@local:~$ go get -d -v .

Compile the source code and create a binary for your target platform.

user@local:~$ go build

Endpoints and usage:

Health:

user@local:~$ curl 127.0.0.1:8080
"ok"

List all users:

user@local:~$ curl 127.0.0.1:8080/users
[{"id":"1","firstname":"James","lastname":"Hetfield","age":56},{"id":"2","firstname":"Lars","lastname":"Ulrich","age":55},{"id":"3","firstname":"Kirk","lastname":"Hammett","age":56},{"id":"4","firstname":"Robert","lastname":"Trujillo","age":55}]

Show single user by ID:

user@local:~$ curl 127.0.0.1:8080/users/1
{"id":"1","firstname":"James","lastname":"Hetfield","age":56}
user@local:~$ curl 127.0.0.1:8080/users/3
{"id":"3","firstname":"Kirk","lastname":"Hammett","age":56}

Add user:

user@local:~$ curl -d '{"id":"5", "firstname":"Tom", "lastname": "Jones", "age":75}' -H "Content-Type: application/json" -X POST http://localhost:8080/users/5
[{"id":"1","firstname":"James","lastname":"Hetfield","age":56},{"id":"2","firstname":"Lars","lastname":"Ulrich","age":55},{"id":"3","firstname":"Kirk","lastname":"Hammett","age":56},{"id":"4","firstname":"Robert","lastname":"Trujillo","age":55},{"id":"5","firstname":"Tom","lastname":"Jones","age":75}]

Delete user:

user@local:~$ curl -X DELETE http://localhost:8080/users/5
[{"id":"1","firstname":"James","lastname":"Hetfield","age":56},{"id":"2","firstname":"Lars","lastname":"Ulrich","age":55},{"id":"3","firstname":"Kirk","lastname":"Hammett","age":56},{"id":"4","firstname":"Robert","lastname":"Trujillo","age":55}]

api's People

Contributors

bjornramberg avatar buck-mbeer avatar setagana avatar

Watchers

James Cloos 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.