Skip to content

This project provides REST APIs for serving hotel details using Node.js, Express.js and TypeScript.

Notifications You must be signed in to change notification settings

aa-nadim/express-hotel-api

Repository files navigation

Hotel Details REST API

This project provides REST APIs for serving hotel details using Node.js, Express.js and TypeScript.

Table of Contents

Features

  • Serve hotel details from JSON file.
  • Robust error handling to prevent app crashes
  • Proper HTTP status codes and response/error messages

Prerequisites

  • Node.js (v14.x or later)

Installation

  1. Clone the repository:

    git clone https://github.com/aa-nadim/express-hotel-api.git
    cd express-hotel-api
  2. Install dependencies:

    npm i

Usage

npm run dev 
npm test

npm test -- tests/hotelController.test.ts

npm test -- tests/imageController.test.ts

API Endpoints

Get all hotels

    URL: /api/hotels
    Method: GET
    Description: Retrieve a list of all hotels.

Get all images

    URL: /api/images
    Method: GET
    Description: Retrieve a list of all images.

Get all rooms

    URL: /api/rooms
    Method: GET
    Description: Retrieve a list of all rooms.

Request

  1. GET /hotels: get all hotels
curl -X GET http://localhost:5000/api/hotels
  1. GET /images: get all images
curl -X GET http://localhost:5000/api/images
  1. GET /rooms: get all rooms
curl -X GET http://localhost:5000/api/rooms
  1. GET /hotel/{hotel-id}:
curl -X GET http://localhost:5000/api/hotel/[hotel-id]
  1. POST /hotel:
curl -X POST http://localhost:5000/api/hotel \
-H "Content-Type: application/json" \
-d '{
  "title": "Luxury Suite Hotel",
  "description": "A beautiful luxury hotel",
  "guestCount": 4,
  "bedroomCount": 2,
  "bathroomCount": 2,
  "amenities": ["wifi", "pool"],
  "host": {
    "name": "John Doe",
    "email": "john@example.com",
    "phone": "+1234567890"
  },
  "address": {
    "street": "123 Main St",
    "city": "New York",
    "state": "NY",
    "country": "USA",
    "zipCode": "10001"
  },
  "location": {
    "latitude": 40.7128,
    "longitude": -74.0060
  }
}'

  1. POST /images:
curl -X POST http://localhost:5000/api/hotel/[hotel-id]/images \
-F "images=@/yourImagePath/image.jpg" \
-F "images=@/yourImagePath/image.png"
  1. PUT /hotel/{hotel-id}:
curl -X PUT http://localhost:5000/api/hotel/[hotel-id] \
-H "Content-Type: application/json" \
-d '{
  "title": "Updated Hotel Name"
}'


curl -X PUT http://localhost:5000/api/hotel/[hotel-id] \
-H "Content-Type: application/json" \
-d '{
   "rooms": [
    {
      "hotelSlug": "dhaka-hotel-5star",
      "roomSlug": "luxury-suite",
      "roomImage": "/uploads/1731392952626-577730834.png",
      "roomTitle": "Luxury Suite",
      "bedroomCount": 1
    },
    {
      "hotelSlug": "dhaka-hotel-5star",
      "roomSlug": "executive-suite",
      "roomImage": "/uploads/1731392952638-468673036.png",
      "roomTitle": "Executive Suite",
      "bedroomCount": 2
    },
    {
      "hotelSlug": "dhaka-hotel-5star",
      "roomSlug": "family-suite",
      "roomImage": "/uploads/1731395511734-205512735.png",
      "roomTitle": "Family Suite",
      "bedroomCount": 2
    },
    {
      "hotelSlug": "dhaka-hotel-5star",
      "roomSlug": "presidential-suite",
      "roomImage": "/uploads/1731395511737-106499270.png",
      "roomTitle": "Presidential Suite",
      "bedroomCount": 3
    }
  ]
}'

About

This project provides REST APIs for serving hotel details using Node.js, Express.js and TypeScript.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published