Create/Update/Delete API by Go.
Development Environment:
- 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.
The API endpoints:
GET /employees
returns all employees in databaseGET /employee/:id
returns the employee by given id if any.POST /employee
creates a new employeeDELETE /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.
Released in public domain. See UNLICENSE.
- golang crud api - Google search↩
golang crud api - DuckDuckGo search
golang crud api - Ecosia search
golang crud api - Qwant search
golang crud api - Bing search
golang crud api - Yahoo search
golang crud api - Baidu search
golang crud api - Yandex search Tutorial: Developing a RESTful API with Go and Gin - The Go Programming Language↩