DEV Community

bobb-Rob
bobb-Rob

Posted on

2

Car "BnB" - API Documentation

baseUrl =_"http://localhost:3001/"

Note:
To access the API you need to sign_up as a user and use the Authorization’s Bearer token to access the other end-points

API End-points

User end points

Sign-up a user

baseUrl/users
Method: Post
parameter : { user: { name: "Freeman", password: "your password" }}

Once you make this request and it is successful, a Bearer token is generated in the response Header - Authorization.
Copy the Bearer token and paste it in the header section of any end-point request with key - Authorization, this will authorize all other request to other end-points as the current user.

Sign in a user

baseUrl/user/sign_in
Method: post
parameter : { user: { name: "Freeman", password: "your password" }}
A Bearer token is also generated once tis request is successfull.

Log out user

baserUrl/user/sign_out
method: delete

Copy the Bearer token from the Signed in user and set it as the value of the Authorization key in the request header.

Car End points

Create Car

baseUrl/cars
method: post
parameter:

{ car: { brand: 'Lexus', model: 'RX 350', year_released: '2021', featured_image: 'your image string link', specifications: 'Your specs' } }

requires token as well

List all Cars

baseUrl/cars
method: get
requires token as well

Delete car

baseUrl/cars/:id
method: delete
parameter is the id of the car.
requires token as well

Reservation Endpoints

Create Reservation

baseUrl/reservations
Method: post
Parameter:

{ city: "Port Harcourt", date: "2022-12-03", car_id: 2, user_id: 9 }

requires token as well

List All Reservations by current user

baseUrl/reservations
Method: get
requires token as well

Delete reservation

baseUrl/reservations/:id
Method: Delete
Parameter is the :id of the reservation to be deleted.
requires token as well

Thank you for using this API

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay