Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/petronetto/echo-mongo-api
Golang Echo's framework with Mongo database
https://github.com/petronetto/echo-mongo-api
docker docker-compose echo go golang mongo rest-api
Last synced: about 2 months ago
JSON representation
Golang Echo's framework with Mongo database
- Host: GitHub
- URL: https://github.com/petronetto/echo-mongo-api
- Owner: petronetto
- License: bsd-3-clause
- Created: 2017-10-10T02:49:49.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-10T02:57:45.000Z (about 7 years ago)
- Last Synced: 2024-06-20T06:29:14.545Z (6 months ago)
- Topics: docker, docker-compose, echo, go, golang, mongo, rest-api
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 12
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Golang API + Mongo database
## Running
Run `docker-compose up -d`## Signup
User signupRetrieve user credentials from the body and validate against database.
For invalid email or password, `send 400 - Bad Request` response.
For valid email and password, save user in database and send `201 - Created` response.Request
```sh
curl \
-X POST \
http://localhost:1323/signup \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","password":"secret"}'
```
Response`201 - Created`
```json
{
"id": "58465b4ea6fe886d3215c6df",
"email": "[email protected]",
"password": "secret"
}
```## Login
User loginRetrieve user credentials from the body and validate against database.
For invalid credentials, send 401 - Unauthorized response.
For valid credentials, send 200 - OK response:
Generate JWT for the user and send it as response.
Each subsequent request must include JWT in the Authorization header.
Method: `POST`
Path: `/login`Request
```sh
curl \
-X POST \
http://localhost:1323/login \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","password":"secret"}'
```
Response`200 - OK`
```json
{
"id": "58465b4ea6fe886d3215c6df",
"email": "[email protected]",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0ODEyNjUxMjgsImlkIjoiNTg0NjViNGVhNmZlODg2ZDMyMTVjNmRmIn0.1IsGGxko1qMCsKkJDQ1NfmrZ945XVC9uZpcvDnKwpL0"
}
```
Client should store the token, for browsers, you may use local storage.## Follow
Follow a userFor invalid token, send 400 - Bad Request response.
For valid token:
If user is not found, send 404 - Not Found response.
Add a follower to the specified user in the path parameter and send 200 - OK response.
Method: POST
Path: /follow/:idRequest
```sh
curl \
-X POST \
http://localhost:1323/follow/58465b4ea6fe886d3215c6df \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0ODEyNjUxMjgsImlkIjoiNTg0NjViNGVhNmZlODg2ZDMyMTVjNmRmIn0.1IsGGxko1qMCsKkJDQ1NfmrZ945XVC9uZpcvDnKwpL0"
```
Response`200 - OK`
## Post
Post a message to specified userFor invalid request payload, send 400 - Bad Request response.
If user is not found, send 404 - Not Found response.
Otherwise save post in the database and return it via 201 - Created response.
Method: `POST`
Path: `/posts`Request
```sh
curl \
-X POST \
http://localhost:1323/posts \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0ODEyNjUxMjgsImlkIjoiNTg0NjViNGVhNmZlODg2ZDMyMTVjNmRmIn0.1IsGGxko1qMCsKkJDQ1NfmrZ945XVC9uZpcvDnKwpL0" \
-H "Content-Type: application/json" \
-d '{"to":"58465b4ea6fe886d3215c6df","message":"hello"}'
```
Response`201 - Created`
```json
{
"id": "584661b9a6fe8871a3804cba",
"to": "58465b4ea6fe886d3215c6df",
"from": "58465b4ea6fe886d3215c6df",
"message": "hello"
}
```## Feed
List most recent messages based on optional page and limit query parametersMethod: `GET`
Path: `/feed?page=1&limit=5`Request
```sh
curl \
-X GET \
http://localhost:1323/feed \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0ODEyNjUxMjgsImlkIjoiNTg0NjViNGVhNmZlODg2ZDMyMTVjNmRmIn0.1IsGGxko1qMCsKkJDQ1NfmrZ945XVC9uZpcvDnKwpL0"
```
Response`200 - OK`
```json
[
{
"id": "584661b9a6fe8871a3804cba",
"to": "58465b4ea6fe886d3215c6df",
"from": "58465b4ea6fe886d3215c6df",
"message": "hello"
}
]
```## License
[BSD 3-Clause](https://github.com/petronetto/echo-mongo-api/blob/master/LICENSE)