Giter Site home page Giter Site logo

tutorial-bikes-api's Introduction

Bikes API, with Cyclic ๐Ÿšฒ๏ธ

Deploy on Cyclic ๐Ÿš€

Deploy to Cyclic

This repository is based on the REST Tutorial you can find here: Getting Started with a RESTful API

Fill Database with Mock Data

npm run fill-db # fills database with 25 mock bike items

Fetching Bikes

GET routes

List all bikes

curl http://localhost:3000/bikes/all | jq .

Get bike by ID

curl http://localhost:3000/bikes/<ID> | jq . # replace <ID> with an ID from the response to /all

Get bike by Handle

curl http://localhost:3000/bikes/by-handle/<HANDLE> | jq . # replace <HANDLE> with a handle from the response to /all

Search bikes by Title

curl http://localhost:3000/bikes/search/by-title\?query\=Bicycle | jq .

Creating and Replacing Bikes (Authentication required!)

POST & PUT routes

Create new bike

// 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"
}
export TOKEN=<TOKEN> # replace <TOKEN> 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

// 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"
}
export TOKEN=<TOKEN> # replace <TOKEN> with the token from /api/user
curl -X PUT -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" http://localhost:3000/bikes/<ID> -d @request.json | jq . # replace <ID> with an ID from the response to /all

Updating and Deleting (Authentication required!)

PATCH & DELETE routes

Update parts of existing bike

// request.json (remove this line from the actual file!)
{
  "totalInventory": 4,
  "availableForSale": true
}
export TOKEN=<TOKEN> # replace <TOKEN> with the token from /api/user
curl -X PATCH -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" http://localhost:3000/bikes/<ID> -d @request.json | jq . # replace <ID> with an ID from the response to /all

Delete existing bike

export TOKEN=<TOKEN> # replace <TOKEN> with the token from /api/user
curl -X DELETE -H "Authorization: Bearer $TOKEN" http://localhost:3000/bikes/<ID> | jq . # replace <ID> with an ID from the response to /all

Authentication

Get bearer authentication token:

curl -H 'Content-Type: application/json' http://localhost:3000/api/user -d '{"username": "cyclic"}' | jq .token -r

tutorial-bikes-api's People

Contributors

youneslaa7878 avatar korostelevm avatar seekayel avatar

Stargazers

Avishek Chatterjee avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.