Skip to content

suvidsahay/GoRestAPI

Repository files navigation

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

About

A user CRUD API written in Golang

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published