This API was created using Golang. To setup the API on your local machine, ensure you have installed at least the go version specified in the go.mod file. Clone the repo and run go mod tidy
.
- Run
go build .
. - Run
./main
. If the server starts and successfully connects to the database, the stringFiber
will be logged in the terminal.
Live base url: [https://task02-ann404014.b4a.run/api]
This is the endpoint that is used to add a new person to the database.
-
/api
-
POST
-
Required
name=[string]Example:
{ "name": "habeeb" }
-
Returns the
ID
of the newly created document and thename
.Status Code:
200
{ "ID": 1, "name": "habeeb" }
This is the endpoint that is used to retrieve the document whose ID
value in the database corresponds to the userID
URL parameter.
-
/api/{userID}
-
GET
-
Required
userID=[int] -
/api/1
-
Status Code:
200
{ "ID": 1, "name": "habeeb" }
-
When the provided
userID
does not match any document in the database.Status Code:
200
{ "error": "No row with found with that id" }
This is the endpoint that is used to change the details of the document whose ID
corresponds with userID
.
-
/api/{userID}
-
PATCH
-
Required
name=[string] -
URL
/api/1
Body
{ "name": "lawal" }
-
Status Code:
200
{ "ID": "1", "name": "habeeb" }
-
When the provided
userID
doesn't match any row in the database.Status Code:
200
{ "error": "No row with found with that id" }
-
When the body of the request cannot be parsed
Status Code:
200
{ "error": "Failed to parse body" }
-
When the provided
userID
is not a valid integer.Status Code:
200
{ "error": "Cannot parse the ID from query" }
This is the endpoint that is used to remove the person document with the corresponding userID from the database.
-
/api/{userID}
-
DELETE
-
Status Code:
200
{ "message": "name of the person with that id" }
-
When the provided
userID
is not a valid integer.Status Code:
200
{ "error": "Cannot parse the ID from query" }
-
When the provided
userID
doesn't match any row in the database.Status Code:
200
{ "error": "No row with found with that id" }