Golang Backend Example - Social Media
This project is written in Go. After learning from Boot.dev Golang courses, trying to implement a simple RESTful backend API with golang standard library net/http
, and using json as the database.
To run this project, type the command below:
git clone https://github.com/SharpKoi/golang-backend-example.git
cd golang-backend-example
go run .
And it will create a localhost server listening on port 8080.
You can use Postman or curl or any else to test this API.
API
Method | URL | Description |
---|---|---|
GET | /api/users | Get all user accounts from database |
GET | /api/users/${email} | Get the user account by user's email |
POST | /api/users | Create an user account by given request body |
PUT | /api/users/${email} | Update the user account by the given email and request body |
DELETE | /api/users/t${email} | Delete user account by the given email |
GET | /api/posts/${email} | Get all the posts created by the user with the given email |
POST | /api/posts | Create a post by given request body |
DELETE | /api/posts/${uuid} | Delete a post by the given uuid |
Here's also a full testing example created at Postman. You can use the given examples to test this API.
TODO
These Ideas below are from the final section of the course, for extending the backend program.
- Use PostgresQL instead of a JSON file for the database layer
- Allow users to save other data with their posts
- Add proper authentication to each request, may use the password validator designed by Lane
- Add more unit tests
- Deploy the API on AWS, GCP, or Digital Ocean
- Dockerize it
- Add documentation using markdown files
- Write a frontend that interacts with the API, maybe a webpage or a mobile app
And these ideas below are mine
- Write a full guide for the backend API designing
- Integrate with discord bot
- Use sentimental analysis to detect the emotion of each post