Git Product home page Git Product logo

adwardstark-go-rest-api's Introduction

go-rest-api

A simple Go based REST API server built using gorilla/mux HTTP router and PostgreSQL database.

Prerequisites


  • Basic familiarity with Go and PostgreSQL, and
  • That you have working Go and Docker installations. You can use Docker to run a test database easily.

Run locally


  • Start PostgreSQL container using:
    $ ./run.sh startdb
  • Once started, initialize database using:
    $ ./run.sh initdb products_db
  • Once initialized, start server using:
    $ ./run.sh server -port=<port_number> # default: 8010
  • Once started, you'll see a message like this:
    Go REST api-server listening on port: 8010
    Press Cmd+C / Ctrl+C to stop.
  • Now launch your browser and go to http://localhost:8010/api/products
  • Once done, stop PostgreSQL container using:
    $ ./run.sh stopdb
  • To clean-up database, use:
    $ ./run.sh cleanup

Test


To run unit tests, start PostgreSQL container then do:

$ ./run.sh test

=== RUN   TestEmptyTable
--- PASS: TestEmptyTable (0.01s)
=== RUN   TestGetNonExistentProduct
--- PASS: TestGetNonExistentProduct (0.00s)
=== RUN   TestCreateProduct
--- PASS: TestCreateProduct (0.01s)
=== RUN   TestGetProduct
--- PASS: TestGetProduct (0.01s)
=== RUN   TestUpdateProduct
--- PASS: TestUpdateProduct (0.02s)
=== RUN   TestDeleteProduct
--- PASS: TestDeleteProduct (0.02s)
PASS
ok  	github.com/adwardstark/go-rest-api/app	0.604s

Endpoints


You can use Postman to perform CURD operations using following endpoints:

  • GET /api/products
  • POST /api/product
  • GET /api/product/{id}
  • PUT /api/product/{id}
  • DELETE /api/product/{id}

License


Apache 2.0. See the LICENSE file for details.

adwardstark-go-rest-api's People

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.