Example of go server. The server expose a rest-api specified in the instruction
The server has a basic authentication. The project has 2 dependencies:
- mattn/go-sqlite3 for connecting to the database
- golang.org/x/crypto for encrypting the passwords
Before running the server is required load the schema file in the database.
For accessing to the api endpoints is required authentication. The data is sent to the server in the header. The auth data sent in the header is the following:
Header Name | Description |
---|---|
username | User name who access to the api |
token | Security token generated by the system after being logged |
/login
{POST} /login
Field | Type | Description |
---|---|---|
user | string | User id |
password | string | Secret password |
Status code 200
Return the authentication credentials for the header
Field | Type | Description |
---|---|---|
user | string | User id (username in the header) |
token | string | Session token |
Status Code 400
Field | Type | Description |
---|---|---|
fields | string[] | List of invalid fields |
message | string | Error message default: "Invalid Input" |
Status Code 401 No output Data
{POST} /signup
Field | Type | Description |
---|---|---|
user | string | User id |
password | string | Secret password |
password2 | string | Secret password |
Status code 200
Field | Type | Description |
---|---|---|
user | string | User id |
token | string | Session token |
Status Code 400
If there are any missing field or password2 doesn't math with password
Field | Type | Description |
---|---|---|
fields | string[] | List of invalid fields |
message | string | Error message default: "Invalid Input" |
{POST} /logout Ends the current user Session
The auth headers are required for this endpoints
Header Name | Description |
---|---|
username | User name who access to the api |
token | Security token generated by the system after being logged |
Status code 200
There are no output data
Status code 400
Field | Type | Description |
---|---|---|
fields | string[] | List of invalid fields |
message | string | Error message default: "Invalid Input" |
Status code 401 Return when the Auth credentials are not validate
There are no output data
{GET} /api/todo
The auth headers are required for this endpoints
Header Name | Description |
---|---|
username | User name who access to the api |
token | Security token generated by the system after being logged |
Status Code 200 List of todo tasks. Each element in the list has the following structure
Field | Type | Description |
---|---|---|
id | integer | Task id |
desc | string | Description of the task |
done | boolean | Flag that indicates if the task is done or not |
user | string | User id who owns the task |
Status code 401 Return when the Auth credentials are not validate
There are no output data
{POST} /api/todo
Get the user todo list
The auth headers are required for this endpoints
Header Name | Description |
---|---|
username | User name who access to the api |
token | Security token generated by the system after being logged |
Field | Type | Description |
---|---|---|
desc | string | Description of the task |
Status Code 201
Field | Type | Description |
---|---|---|
id | integer | Task id |
desc | string | Description of the task |
done | boolean | Flag that indicates if the task is done or not |
user | string | User id who owns the task |
Status code 400
Field | Type | Description |
---|---|---|
fields | string[] | List of invalid fields |
message | string | Error message default: "Invalid Input" |
Status code 401 Return when the Auth credentials are not validate
There are no output data
{PUT} /api/todo/:taskId
Update the status of a task.
The auth headers are required for this endpoints
Header Name | Description |
---|---|
username | User name who access to the api |
token | Security token generated by the system after being logged |
Field | Type | Description |
---|---|---|
done | boolean | Flag that indicates if the task is done or not |
Status Code 200
Field | Type | Description |
---|---|---|
success | boolean | Flag that indicates if the action was done |
Status code 400
Field | Type | Description |
---|---|---|
fields | string[] | List of invalid fields |
message | string | Error message default: "Invalid Input" |
Status code 401 Return when the Auth credentials are not validate
There are no output data
Status code 404 Return when the taskId doesn't exist or when the task is assigned to other user
There are no output data
{DELETE} /api/todo/:taskId
The auth headers are required for this endpoints
Header Name | Description |
---|---|
username | User name who access to the api |
token | Security token generated by the system after being logged |
Status Code 200
Field | Type | Description |
---|---|---|
success | boolean | Flag that indicates if the action was done |
Status code 401 Return when the Auth credentials are not validate
Status code 404 Return when the taskId doesn't exist or when the task is assigned to other user