Back end for a message board application, written in Go with PostgreSQL and Docker. An instance of this application will be running on AWS for the month of November at http://gabrielb.eu-central-1.elasticbeanstalk.com
This application requires Docker Compose and Docker
-
run locally :
docker-compose up
- may require sudo privileges. Starts a docker container running Postgres, listening on port 5432, and a docker container running an HTTP web server listening on port 8080. -
run unit tests :
docker-compose -f docker-compose.test.yml up
- This will run the tests located in server/app/app_test.go -
run integration tests :
python3 test/apitest.py
- By default, tests assume the server is running on http://localhost:8080. To specify a different URL, include it as the first command line argument - ex:python3 test/apitest.py http://gabrielb.eu-central-1.elasticbeanstalk.com
The CSV file database/messages.csv is automatically loaded into the database on application startup. If you modify this file, make sure to rebuild the docker images by running docker-compose rm -f
then docker-compose build
.
The message board backend exposes a public and a private RESTful API. Both APIs accept JSON-encoded request bodies, and return JSON-encoded responses, using standard HTTP response codes and verbs.
-
Create Message :
POST /messages
-
List All Messages :
GET /messages
-
Get Message By ID :
GET /messages/{ID}
-
Update Message Text :
PUT /messages/{ID}
HTTP basic authentication is used to validate HTTP requests.
URL : /messages
Method : POST
Auth required : NO
Data constraints
Provide name, email, and text of message to be created:
{
"name": "[unicode]",
"email": "[unicode]",
"text": "[unicode]"
}
Condition : Everything is OK, message created successfully
Code : 201 CREATED
Content example
{
"id": "26332274-277e-11eb-a10f-02f45a9cb7ee",
"name": "gabe",
"email": "test@gmail.com",
"text": "example text",
"creation_time": "2020-11-15T20:07:12.509223Z"
}
Condition : JSON message was malformed
Code : 400 BAD REQUEST
URL : /messages
Method : GET
Auth required : YES
Data constraints : None
Condition : 0 or more messages retrieved
Code : 200 OK
Content example
[
{
"id": "26332275-277e-11eb-a10f-02f45a9cb7ee",
"name": "gabe",
"email": "test@gmail.com",
"text": "example text",
"creation_time": "2020-11-15T20:07:12.509223Z"
},
{
"id": "26332274-277e-11eb-a10f-02f45a9cb7ee",
"name": "gabe",
"email": "test@gmail.com",
"text": "another message",
"creation_time": "2020-10-15T20:07:12.509223Z"
},
{
"id": "26332271-277e-11eb-a10f-02f45a9cb7ee",
"name": "gabe",
"email": "test@gmail.com",
"text": "yet anothe message",
"creation_time": "2019-11-15T20:07:12.509223Z"
},
]
Condition : Incorrect Authorization
Code : 401 UNAUTHORIZED
URL : /messages/{id}
Method : GET
Auth required : YES
Data constraints : None
Condition : Message retrieved
Code : 200 OK
Content example
{
"id": "26332274-277e-11eb-a10f-02f45a9cb7ee",
"name": "gabe",
"email": "test@gmail.com",
"text": "example text",
"creation_time": "2020-11-15T20:07:12.509223Z"
}
Condition : Incorrect Authorization
Code : 401 UNAUTHORIZED
Condition : ID not found in database
Code : 404 Not Found
Condition : UUID is malformed
Code : 500 Internal Server Error
URL : /messages/{id}
Method : PUT
Auth required : YES
Data constraints
Provide new text:
{
"text": "[unicode]"
}
Condition : Message updated successfully
Code : 200 OK
Content example
{
"id": "26332274-277e-11eb-a10f-02f45a9cb7ee",
"name": "gabe",
"email": "test@gmail.com",
"text": "updated text",
"creation_time": "2020-11-15T20:07:12.509223Z"
}
Condition : Incorrect Authorization
Code : 401 UNAUTHORIZED
Condition : JSON message was malformed
Code : 400 BAD REQUEST
Condition : ID not found in database
Code : 404 Not Found
Condition : UUID is malformed
Code : 500 Internal Server Error