Skip to content

SSinghNet/hacknjit2024

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Documentation

Welcome to the API documentation for our application. This document provides detailed information about the available endpoints for managing Items and Users. The API is built using Express.js and Firebase Firestore.

Table of Contents


Base URL

All endpoints are prefixed with the base URL of your server. For example:

https://your-domain.com/api

Replace https://your-domain.com/api with your actual server URL.

Authentication

Note: The current endpoints do not implement authentication. For secure applications, consider adding authentication mechanisms like JWT or OAuth.


Endpoints

Items

Get All Items

Retrieve a list of all items.

  • URL: /items
  • Method: GET
  • URL Parameters: None
  • Body Parameters: None

Success Response:

  • Code: 200 OK
  • Content:
    [
      {
        "id": "item1",
        "name": "Item One",
        "description": "Description of Item One"
      },
      {
        "id": "item2",
        "name": "Item Two",
        "description": "Description of Item Two"
      }
    ]

Error Response:

  • Code: 500 Internal Server Error
  • Content:
    {
      "error": "Error message"
    }

Get Item by ID

Retrieve a single item by its ID.

  • URL: /items/:id
  • Method: GET
  • URL Parameters:
    • id (string): The ID of the item to retrieve.
  • Body Parameters: None

Success Response:

  • Code: 200 OK
  • Content:
    {
      "id": "item1",
      "name": "Item One",
      "description": "Description of Item One"
    }

Error Response:

  • Code: 404 Not Found
  • Content:
    {
      "error": "No Item Found"
    }

Create a New Item

Add a new item to the database.

  • URL: /items
  • Method: POST
  • URL Parameters: None
  • Body Parameters:
    • name (string): Name of the item.
    • description (string): Description of the item.

Request Body Example:

{
  "name": "Item One",
  "description": "Description of Item One"
}

Success Response:

  • Code: 200 OK
  • Content:
    {
      "name": "Item One",
      "description": "Description of Item One"
    }

Error Response:

  • Code: 500 Internal Server Error
  • Content:
    {
      "error": "Invalid Item Schema"
    }

Users

Get User by ID

Retrieve a single user by their ID.

  • URL: /users/:id
  • Method: GET
  • URL Parameters:
    • id (string): The ID of the user to retrieve.
  • Body Parameters: None

Success Response:

  • Code: 200 OK
  • Content:
    {
      "id": "user1",
      "username": "UserOne",
      "email": "userone@example.com"
    }

Error Response:

  • Code: 404 Not Found
  • Content:
    {
      "error": "No User Found"
    }

Get User's Items

Retrieve all items associated with a specific user.

  • URL: /users/:id/items
  • Method: GET
  • URL Parameters:
    • id (string): The ID of the user whose items are to be retrieved.
  • Body Parameters: None

Success Response:

  • Code: 200 OK
  • Content:
    [
      "item1",
      "item2"
    ]

Error Response:

  • Code: 404 Not Found
  • Content:
    {
      "error": "No User Found"
    }

Create a New User

Add a new user to the database.

  • URL: /users
  • Method: POST
  • URL Parameters: None
  • Body Parameters:
    • username (string): Username of the user.
    • email (string): Email address of the user.

Request Body Example:

{
  "username": "UserOne",
  "email": "userone@example.com"
}

Success Response:

  • Code: 200 OK
  • Content:
    {
      "username": "UserOne",
      "email": "userone@example.com",
      "items": []
    }

Error Response:

  • Code: 500 Internal Server Error
  • Content:
    {
      "error": "Invalid User Schema"
    }

Error Handling

All error responses follow a consistent format:

{
  "error": "Error message"
}
  • 500 Internal Server Error: Indicates a server-side issue, such as an invalid schema or database error.
  • 404 Not Found: Indicates that the requested resource (Item or User) does not exist.

Data Models

Item

Represents an item in the database.

Field Type Description
id string Unique identifier for the item.
name string Name of the item.
description string Description of the item.

TypeScript Interface

export interface Item {
  id: string;
  name: string;
  description: string;
}

User

Represents a user in the database.

Field Type Description
id string Unique identifier for the user.
username string Username of the user.
email string Email address of the user.
items string[] Array of item IDs associated with the user.

TypeScript Interface

export interface User {
  id: string;
  username: string;
  email: string;
  items: string[];
}

Examples

Get All Items Example

Request:

GET /items HTTP/1.1
Host: your-domain.com

Response:

[
  {
    "id": "item1",
    "name": "Item One",
    "description": "Description of Item One"
  },
  {
    "id": "item2",
    "name": "Item Two",
    "description": "Description of Item Two"
  }
]

Get Item by ID Example

Request:

GET /items/item1 HTTP/1.1
Host: your-domain.com

Response:

{
  "id": "item1",
  "name": "Item One",
  "description": "Description of Item One"
}

Error Response:

{
  "error": "No Item Found"
}

Create a New Item Example

Request:

POST /items HTTP/1.1
Host: your-domain.com
Content-Type: application/json

{
  "name": "Item Three",
  "description": "Description of Item Three"
}

Response:

{
  "name": "Item Three",
  "description": "Description of Item Three"
}

Error Response:

{
  "error": "Invalid Item Schema"
}

Get User by ID Example

Request:

GET /users/user1 HTTP/1.1
Host: your-domain.com

Response:

{
  "id": "user1",
  "username": "UserOne",
  "email": "userone@example.com"
}

Error Response:

{
  "error": "No User Found"
}

Get User's Items Example

Request:

GET /users/user1/items HTTP/1.1
Host: your-domain.com

Response:

[
  "item1",
  "item2"
]

Error Response:

{
  "error": "No User Found"
}

Create a New User Example

Request:

POST /users HTTP/1.1
Host: your-domain.com
Content-Type: application/json

{
  "username": "UserTwo",
  "email": "usertwo@example.com"
}

Response:

{
  "username": "UserTwo",
  "email": "usertwo@example.com",
  "items": []
}

Error Response:

{
  "error": "Invalid User Schema"
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •