Skip to content

molmedoz/GO-TODO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TODO List

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

End points

/login

Login

{POST} /login

Body

Field Type Description
user string User id
password string Secret password

Success

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

Error

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

SingUp

{POST} /signup

Body

Field Type Description
user string User id
password string Secret password
password2 string Secret password

Success

Status code 200

Field Type Description
user string User id
token string Session token

Error

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"

Logout

{POST} /logout Ends the current user Session

Headers

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

Success

Status code 200

There are no output data

Error

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

TaskList

{GET} /api/todo

Headers

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

Success

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

Error

Status code 401 Return when the Auth credentials are not validate

There are no output data

Add Task

{POST} /api/todo

Get the user todo list

Headers

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

Body

Field Type Description
desc string Description of the task

Success

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

Error

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

Update Task

{PUT} /api/todo/:taskId

Update the status of a task.

Headers

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

Body

Field Type Description
done boolean Flag that indicates if the task is done or not

Success

Status Code 200

Field Type Description
success boolean Flag that indicates if the action was done

Error

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 Task

{DELETE} /api/todo/:taskId

Headers

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

Success

Status Code 200

Field Type Description
success boolean Flag that indicates if the action was done

Error

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

About

GO REST server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages