Travel-Book API Documentation

Travel-Book API Documentation

Travel-Book is a web application built using the MERN stack (MongoDB, Express, React, and Node.js).

ยท

4 min read

To check out the project click on Travel-Book .

The web application offers several features, starting with CRUD operations that allow users to create, read, update, and delete their stories. Users can also share their stories with friends by generating a unique URL. Additionally, they can download the image of their story and share it on their Instagram Story. (We are still working on this feature, using the HTML2CANVAS library for image generation.)

The overview of the routes with their Methods.

Let's go over the API documentation for this web application, so other developers can easily interact with the backend using Postman or any other platform. This will allow them to perform API operations and learn about RESTful APIs. The backend of the project is hosted on the Render platform.

The Backend Base URL is Travel-Book-Backend-URL

We will go over each route in detail, covering their respective domains, such as Authentication, Story Creation, Update, Deletion, Reading, and Image Upload.

๐Ÿ› ๏ธ Authentication in Travel-Book โ†’

Users can authenticate themselves by providing their Email-ID and Password.

To log in, users need to enter their Email-ID and Password to access their Travel Book.

To create an account, users need to provide their Full Name, Email-ID, and Password.

  1. Register a New User :

Endpoint: POST /create-account

Description: Creates a new user account.

Request Body:

{

"fullName": "John Doe",

"email": "john@example.com",

"password": "securepassword"

}

Response:

{

"error": false,

"user": { "fullName": "John Doe", "email": "john@example.com" },

"accessToken": "your-jwt-token",

"message": "Successfully Registered for a Travel Book!"

}

  1. Login User :

Endpoint : POST /login

Description: Logs in a user and returns a JWT token.

Request Body:

{

"email": "john@example.com",

"password": "securepassword"

}

Response:

{

"error": false,

"message": "Login Successfully to Travel Book",

"user": { "fullName": "John Doe", "email": "john@example.com" },

"accessToken": "your-jwt-token"

}

  1. Get User Profile :

Endpoint: GET /get-user

Description: Fetches user details.
Authentication Required: โœ… Yes (JWT Token)

Headers:

{

"Authorization": "Bearer your-jwt-token"

}

Response:

{

"user": { "_id": "1234", "fullName": "John Doe",

"email": "john@example.com"}

}

๐Ÿ“ Travel Story Routes โ†’

The user will get all the stories information and appending new story or deleting stories features from the below routes.

  1. Add a Travel Story :

Endpoint: POST /add-travel-story
Description: Adds a new travel story.
Authentication Required: โœ… Yes

Request Body:

{

"title": "Trip to Paris",

"story": "Visited the Eiffel Tower!",

"visitedLocation": "Paris",

"imageUrl": "https://example.com/image.jpg",

"visitedDate": "1704045623000"

}

Response:

{

"story": { "title": "Trip to Paris",

"visitedLocation": "Paris" },

"message": "Added Successfully"

}

  1. Get all Travel Stories :

Endpoint: GET /get-all-stories
Description: Fetches all travel stories of the logged-in user.
Authentication Required: โœ… Yes

Response:

{

"stories": [ { "_id": "123", "title": "Trip to Paris",

"visitedLocation": "Paris",

"isFavourite": false } ]

}

  1. Edit a Travel Story :

Endpoint: PUT /edit-story/:id
Description: Edits an existing travel story.
Authentication Required: โœ… Yes

Request Body:

{

"title": "Updated Title",

"story": "Updated Story",

"visitedLocation": "New Location",

"imageUrl": "https://example.com/new-image.jpg",

"visitedDate": "1704045623000"

}

Response:

{

"story": { "title": "Updated Title",

"visitedLocation": "New Location" },

"message": "Update Successful"

}

  1. Delete a Travel Story :

Endpoint: DELETE /delete-story/:id
Description: Deletes a travel story.
Authentication Required: โœ… Yes

Response:

{

"message": "Travel Story deleted successfully!"

}

๐Ÿ“ท Image Upload Routes โ†’

The user can upload the images of the place that they have visited from the below routes where we have used Cloudinary to store the images.

  1. Upload an Image :

Endpoint: POST /image-upload
Description: Uploads an image to Cloudinary.
Authentication Required: โŒ No

Request (multipart/form-data)

Key: image

Value: (Select an image file)

Response:

{

"imageUrl": "https://cloudinary.com/travelbook/image.jpg"

}

โญ Favorite and Search Routes โ†’

Endpoint: PUT /update-is-favourite/:id
Description: Marks a story as a favorite.
Authentication Required: โœ… Yes

Request Body:

{

"isFavourite": true

}

Response:

{

"story": { "title": "Trip to Paris", "isFavourite": true },

"message": "Update Successful"

}

๐Ÿ” Search Travel Stories โ†’

Endpoint: GET /search?query=Paris
Description: Searches for travel stories by title, location, or description.
Authentication Required: โœ… Yes

Response:

{

"stories": [ { "_id": "123", "title": "Trip to Paris",

"visitedLocation": "Paris" } ]

}

๐Ÿ“… Filter By Date โ†’

Endpoint: GET /travel-stories-filter?startDate=1704045623000&endDate=1707045623000
Description: Filters travel stories by a date range.
Authentication Required: โœ… Yes

Response:

{

"stories": [ { "title": "Trip to Paris",

"visitedDate": "2024-01-01T00:00:00.000Z" } ]

}

๐Ÿ”— Share Travel Stories โ†’

Endpoint: GET /api/story/:id
Description: Fetches a specific travel story for public sharing.
Authentication Required: โŒ No

{

"_id": "123",

"title": "Trip to Paris",

"story": "Visited the Eiffel Tower",

"visitedLocation": "Paris"

}

โš ๏ธ Error Handling

Status CodeMeaningExample Cause
400Bad RequestMissing required fields
401UnauthorizedMissing or invalid JWT token
403ForbiddenAccess denied
404Not FoundStory ID doesn't exist
500Server ErrorInternal backend issue

๐Ÿš€ Deployment

For more information or to connect with me, feel free to check out my portfolio, GitHub, LinkedIn, and Twitter:

ย