An open API service indexing awesome lists of open source software.

https://github.com/cuuupid/crud-boilerplate


https://github.com/cuuupid/crud-boilerplate

Last synced: about 1 month ago
JSON representation

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
}
```