https://github.com/cuuupid/crud-boilerplate
https://github.com/cuuupid/crud-boilerplate
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/cuuupid/crud-boilerplate
- Owner: cuuupid
- Created: 2019-12-09T01:49:10.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-22T13:24:27.000Z (over 2 years ago)
- Last Synced: 2025-02-07T21:44:52.394Z (3 months ago)
- Language: JavaScript
- Size: 83 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CRUD Boilerplate
A basic CRUD Express+Mongo stack API.
**Routes** - `routes/`
**DB Schemas/Models** - `models/`
**Entrypoint** - `app.js`
Users have a basic model - email, password, and a name. Passwords are hashed with BCrypt.
# API
API Version: `v1`
All endpoints are of form:
`http(s)://:/v1/`
For example running it locally,
`http://localhost:3000/v1/status`All endpoints return errors in the format:
```
{
"error": "message"
}
```
Please take note that common HTTP error codes are used.Basic security is implemented - Helmet and SlowDown on the app, and JWT on the API.
## Endpoints
### Status
- Method: `GET`
- Params: none
- Headers: none
- Path: `/status`Example:
``` bash
curl --request GET \
--url http://localhost:3000/v1/status
```### Create
- Method: `POST`
- Params: email, password, name (in JSON)
- Headers:
- `Content-Type: application/json`
- Path: `/signup`Example:
``` bash
curl --request POST \
--url http://localhost:3000/v1/signup \
--header 'content-type: application/json' \
--data '{
"email": "[email protected]",
"password": "password",
"name": "Example 1"
}'
```Returns:
``` json
{
"success": true
}
```### Auth
- Method: `POST`
- Params: email, password (in JSON)
- Headers:
- `Content-Type: application/json`
- Path: `/login`Example:
``` bash
curl --request POST \
--url http://localhost:3000/v1/login \
--header 'content-type: application/json' \
--data '{
"email": "[email protected]",
"password": "password"
}'
```Returns:
``` json
{
"accessToken": "your token here"
}
```
You can now use this token for further authenticated requests.### Read
- Method: `POST`
- Params: none
- Headers:
- `Content-Type: application/json`
- `x-access-token: your token here`
- Path: `/me`Example:
``` bash
curl --request POST \
--url http://localhost:3000/v1/me \
--header 'x-access-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVkZWRiNTBkMjk4ZTc5MDBjYTgxY2M1YyIsImlhdCI6MTU3NTg1OTU3MiwiZXhwIjoxNTc1OTQ1OTcyfQ.qu51CQ8GidBOk4W--AaKQ96-Fv1XjQ6HXXAcbi2SEBk'
```Returns:
``` json
{
"_id": "5dedb91b298e7900ca81cc5e",
"email": "[email protected]",
"name": "Example 1"
}
```### Update
- Method: `POST`
- Params: name, email (in JSON) (all optional)
- Headers:
- `Content-Type: application/json`
- `x-access-token: your token here`
- Path: `/update`Example:
``` bash
curl --request POST \
--url http://localhost:3000/v1/update \
--header 'content-type: application/json' \
--header 'x-access-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVkZWRiOTFiMjk4ZTc5MDBjYTgxY2M1ZSIsImlhdCI6MTU3NTg2MDUxMiwiZXhwIjoxNTc1OTQ2OTEyfQ.ssRAlJRghnjkb58Gb3bMq2CpUmF8jrujqKtsCRjwWa4' \
--data '{
"name": "Example 2",
"email": "[email protected]"
}'
```Returns:
``` json
{
"_id": "5dedb91b298e7900ca81cc5e",
"email": "[email protected]",
"name": "Example 2"
}
```### Delete
- Method: `POST`
- Params: email, password (in JSON)
- Headers:
- `Content-Type: application/json`
- `x-access-token: your token here`
- Path: `/delete`**Caution: this is permanent!**
Example:
``` bash
curl --request POST \
--url http://localhost:3000/v1/delete \
--header 'content-type: application/json' \
--header 'x-access-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVkZWRiOTFiMjk4ZTc5MDBjYTgxY2M1ZSIsImlhdCI6MTU3NTg2MDUxMiwiZXhwIjoxNTc1OTQ2OTEyfQ.ssRAlJRghnjkb58Gb3bMq2CpUmF8jrujqKtsCRjwWa4' \
--data '{
"email": "[email protected]",
"password": "password"
}'
```Returns:
``` json
{
"success": true
}
```