siongui / go-employee-api

Go Employee Open API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Golang Employee Open API

image

image

image

image

image

Create/Update/Delete API by Go.

Development Environment:

Requirement

  • Create API
    • Request - RequestId, Emp name, age, address, gender, department, mobile number (The mandatory fields are based on your assumption)
    • Response - RequestId, Errorcode, Errordesc, empid, empname
  • Update API
    • Request - RequestId, Emp id, Emp name, age, address, gender, department, mobile number
    • Response - RequestId, Errorcode, Errordesc, empid
  • Delete API
    • Request - RequestId, Emp id
    • Response - RequestId, Errorcode, Errordesc, empid
  • Use Postgres DB, bun to connect DB.
  • Log debug / info is required. (Using logrus)
  • Unit Testing is required.

Usage

Use gin to create CRUD12 API.

The API endpoints:

  • GET /employees returns all employees in database
  • GET /employee/:id returns the employee by given id if any.
  • POST /employee creates a new employee
  • DELETE /employee/:id deletes the employee by given id if any.
  • PUT /employee updates the employee

Use curl to try the API endpoints:

# Get all employees
$ curl http://localhost:8080/employees
# Create a new employee
$ curl http://localhost:8080/employee \
  --include \
  --header "Content-Type: application/json" \
  --request "POST" \
  --data '{"id": 3,"name": "Sawadee","title": "Senior Engineer"}'
# Read a new employee whose id is 1
$ curl http://localhost:8080/employee/1
# Delete the employee whose id is 1
$ curl http://localhost:8080/employee/1 \
  --request "DELETE"
# Update the employee whose id is 1
$ curl http://localhost:8080/employee \
  --include \
  --header "Content-Type: application/json" \
  --request "PUT" \
  --data '{"id": 1,"name": "MyUpdatedName","title": "CEO"}'

See Makefile for more curl examples.

UNLICENSE

Released in public domain. See UNLICENSE.

References


  1. Tutorial: Developing a RESTful API with Go and Gin - The Go Programming Language

About

Go Employee Open API

License:The Unlicense


Languages

Language:Go 78.7%Language:Makefile 21.3%