Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ayine-nongre/hngx-stage-two-simple-crud-api
https://github.com/ayine-nongre/hngx-stage-two-simple-crud-api
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/ayine-nongre/hngx-stage-two-simple-crud-api
- Owner: Ayine-nongre
- Created: 2023-09-10T20:24:25.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-13T17:57:20.000Z (about 1 year ago)
- Last Synced: 2023-09-14T08:28:15.032Z (about 1 year ago)
- Language: JavaScript
- Size: 3.31 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HNGx-stage-two-simple-CRUD-API
## Introduction
This API allows users to make CRUD operations such as create, read, update and delete on a person stored in mongodb database## Setup and usage
### 1. Clone repo:
```
git clone
```
### 2. Install dependencies in package.json:
```
npm install [dependecies]
```
### 3. Create .env file and set db server:
```
DB_SERVER = "mongodb://127.0.0.1:27017/person"
```
### 4. Run command below to start:
```
npm run server
```## Base URL
https://hngx-ayinenongre.onrender.com## Endpoints
### 1. Add a person
Endpoint: /api
Description: Adds a person to a database
Example use case:
https://hngx-ayinenongre.onrender.com/api
### Body:
```
{
name: ayine-nongre
}
```
### Response:
#### Success:
```
{
name: ayine-nongre
id: 123
}
```
### Failure:
```
{
Message: Make sure all spaces are filled
}
```
#### Error:
```
{
Message: Error creating person
}
```### 2. Get a person
Endpoint: /api/:user_id
Description: Gets a person from databaseExample use case:
https://hngx-ayinenongre.onrender.com/api/ayine-nongre
### Response:
#### Success:
```
{
name: ayine-nongre
id: 123
}
```
### Failure:
```
{
Message: There are no records of user with name ayine-nongre
}
```#### Error:
```
{
Message: Error fetching person
}
```### 3. Update a person
Endpoint: /api/:user_id
Description: Deletes a person from databaseExample use case:
https://hngx-ayinenongre.onrender.com/api/ayine-nongre
### Body:
```
{
name: Jake
}
```
### Response:
#### Success:
```
{
name: Jake
id: 123
}
```
### Failure:
```
{
Message: No new data passed to be updated
}
```#### Error:
```
{
Message: Error updating person
}
```### 4. Delete a person
Endpoint: /api/:user_id
Description: Deleres a person from databaseExample use case:
https://hngx-ayinenongre.onrender.com/api/Jake
### Response:
#### Success:
```
{
name: Jake
id: 123
}
```
### Failure:
```
{
Message: Can't delete person if name is not given
}
```#### Error:
```
{
Message: Error deleting person
}
```