Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eludadev/bikes-api
RESTful Bikes Shop API, powered by Cyclic.
https://github.com/eludadev/bikes-api
api api-rest first-contributions hacktoberfest rest serverless template
Last synced: 2 days ago
JSON representation
RESTful Bikes Shop API, powered by Cyclic.
- Host: GitHub
- URL: https://github.com/eludadev/bikes-api
- Owner: eludadev
- License: mit
- Created: 2022-09-28T19:19:20.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-08T20:02:31.000Z (almost 2 years ago)
- Last Synced: 2023-04-24T15:36:13.961Z (over 1 year ago)
- Topics: api, api-rest, first-contributions, hacktoberfest, rest, serverless, template
- Language: HTML
- Homepage: https://bikes.cyclic.app/
- Size: 3.19 MB
- Stars: 2
- Watchers: 2
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bikes API, with Cyclic 🚲️
## Deploy on Cyclic 🚀
[![Deploy to Cyclic](https://deploy.cyclic.sh/button.svg)](https://deploy.cyclic.sh/eludadev/bikes-api)
## Fill Database with Mock Data
```bash
npm run fill-db # fills database with 25 mock bike items
```## Fetching Bikes
![GET routes](./assets/GET%20Routes.png)### List all bikes
```bash
curl http://localhost:3000/bikes/all | jq .
```### Get bike by ID
```bash
curl http://localhost:3000/bikes/ | jq . # replace with an ID from the response to /all
```### Get bike by Handle
```bash
curl http://localhost:3000/bikes/by-handle/ | jq . # replace with a handle from the response to /all
```### Search bikes by Title
```bash
curl http://localhost:3000/bikes/search/by-title\?query\=Bicycle | jq .
```## Creating and Replacing Bikes [(Authentication required!)](#authentication)
![POST & PUT routes](./assets/POST%20%26%20PUT%20Routes.png)### Create new bike
```json
// request.json (remove this line from the actual file!)
{
"productType": "Hybrid Bicycle",
"createdAt": "Fri Jan 28 2022 03:13:24 GMT+0100 (GMT+02:00)",
"vendor": "Audi",
"totalInventory": 2,
"availableForSale": false,
"priceRange": {
"minPrice": {
"currencyCode": "USD",
"amount": 1160
},
"maxPrice": {
"currencyCode": "USD",
"amount": 1624
}
},
"description": "Autem ipsam quasi omnis ut. Et officiis quia. Sed quaerat pariatur nihil nobis est quos earum quidem.",
"title": "Hybrid Bicycle Sentra"
}
``````bash
export TOKEN= # replace with the token from /api/user
curl -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" http://localhost:3000/bikes/ -d @request.json | jq .
```### Replace existing bike
```json
// request.json (remove this line from the actual file!)
{
"productType": "Hybrid Bicycle",
"createdAt": "Fri Jan 28 2022 03:13:24 GMT+0100 (GMT+02:00)",
"vendor": "Audi",
"totalInventory": 2,
"availableForSale": false,
"priceRange": {
"minPrice": {
"currencyCode": "USD",
"amount": 1160
},
"maxPrice": {
"currencyCode": "USD",
"amount": 1624
}
},
"description": "Autem ipsam quasi omnis ut. Et officiis quia. Sed quaerat pariatur nihil nobis est quos earum quidem.",
"title": "Hybrid Bicycle Sentra",
"id": "4139c5ae-b83d-4a0c-9b75-12d182aaed7c",
"handle": "hybrid-bicycle-sentra"
}
``````bash
export TOKEN= # replace with the token from /api/user
curl -X PUT -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" http://localhost:3000/bikes/ -d @request.json | jq . # replace with an ID from the response to /all
```## Updating and Deleting [(Authentication required!)](#authentication)
![PATCH & DELETE routes](./assets/PATCH%20%26%20DELETE%20Routes.png)### Update parts of existing bike
```json
// request.json (remove this line from the actual file!)
{
"totalInventory": 4,
"availableForSale": true
}
``````bash
export TOKEN= # replace with the token from /api/user
curl -X PATCH -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" http://localhost:3000/bikes/ -d @request.json | jq . # replace with an ID from the response to /all
```### Delete existing bike
```bash
export TOKEN= # replace with the token from /api/user
curl -X DELETE -H "Authorization: Bearer $TOKEN" http://localhost:3000/bikes/ | jq . # replace with an ID from the response to /all
```## Authentication
Get bearer authentication token:
```bash
curl -H 'Content-Type: application/json' http://localhost:3000/api/user -d '{"username": "cyclic"}' | jq .token -r
```