Skip to content

Latest commit

 

History

History
executable file
·
64 lines (49 loc) · 1.3 KB

README.md

File metadata and controls

executable file
·
64 lines (49 loc) · 1.3 KB

Rest API Written in Golang

Setting up a development environment

# Get the code
git clone https://github.com/suvidsahay/GoRestAPI Factly
cd Factly

Configuration

Postgres database setup

Assuming that Postgres(v12 or later) is installed:

  • Create role:
    sudo -u postgres createuser -P factly     # prompts for password
  • Create database:
    sudo -u postgres createdb -O factly factly

Configuration

Create .env file based in sample.env and change the password provided while creating the factly user

Starting the web server

The web server can be started as shown below(assuming Go 1.13 is installed. By default it listens for HTTP connections on port 5000, so point your client at localhost:5000.

go run main.go

Consuming the REST API endpoints

  • GET /users
curl -XGET localhost:5000/users
  • POST /user
curl -XPOST -d '{"name":"Something"}' -H 'Content-Type: application/json' localhost:5000/user
  • PUT /user/{id}
curl -XPUT -d '{"name":"New Name"}' -H 'Content-Type: application/json' localhost:5000/user/1
  • DELETE /user/{id}
curl -XDELETE localhost:5000/user/1

Unit Testing using Go testing package

Run the following to command to test your application

go test -v