This document provides an overview of the Storage API, a versatile data storage and retrieval system. The API supports multiple versions, with distinct features and underlying storage mechanisms.
The v1 version of the API use a local storage system, saving data directly to the server's static file system.
Files are stored in the directory specified in api.config.js
in the documentsFolder
field.
This version is suitable for scenarios where a simple local storage solution is sufficient.
The v2 version of the API employs the Firebase storage system, allowing for cloud-based data storage.
This version is well-suited for applications that require scalable and reliable cloud storage.
You need to provide the Firebase service account key in the firebaseServiceAccountKey
field in api.config.js
and create a collection in the Firebase database with the name specified in the collectionName
field.
Feel free to create and add to this repository your own version with different providers and storage systems.
You can create a new version by duplicating the v2
folder and modifying the code to suit your specific use case.
In the api.config.js
file, you can specify the configuration for your API:
const apiConfiguration = {
baseUrl: 'http://localhost',
port: 3000,
apiVersion: 'v1',
documentsFolder: 'static/documents',
firebaseServiceAccountKey: undefined,
collectionName: 'products',
}
module.exports = apiConfiguration;
baseUrl
: The base URL of the API.port
: The port number for the API server.apiVersion
: Specifies the API version to use ('v1' or 'v2').documentsFolder
: The folder path for storing documents in the Static Storage System.firebaseServiceAccountKey
: The Firebase service account key for API version 2.collectionName
: The name of the main collection (Should be the same as the collection name in the Firebase database).
{version}
: The API version ('v1' or 'v2').
- HTTP Method: POST
- Request Body:
title
: Title of the document.description
: Description of the document.price
: Price of the document.images
: Images associated with the document.collection
: Collection of the document.
- Response:
- 201 Created: Returns the newly created document in JSON format.
- 400 Bad Request: If required parameters are missing in the request body.
- 500 Internal Server Error: If an error occurs during the creation process.
- HTTP Method: GET
- Parameters:
{version}
: The API version ('v1' or 'v2').
- Response:
- 200 OK: Returns an array of all documents in JSON format.
- 500 Internal Server Error: If an error occurs during the retrieval process.
- HTTP Method: GET
- Parameters:
{version}
: The API version ('v1' or 'v2').:id
: The unique identifier of the document.
- Response:
- 200 OK: Returns the details of the document in JSON format.
- 404 Not Found: If the document with the specified ID is not found.
- 500 Internal Server Error: If an error occurs during the retrieval process.
- HTTP Method: POST
- Parameters:
{version}
: The API version ('v1' or 'v2').:id
: The unique identifier of the document.
- Request Body:
- Specify the fields to be updated in the document.
- Response:
- 200 OK: Returns a success message and the updated document in JSON format.
- 404 Not Found: If the document with the specified ID is not found.
- 500 Internal Server Error: If an error occurs during the update process.
- HTTP Method: DELETE
- Parameters:
{version}
: The API version ('v1' or 'v2').:id
: The unique identifier of the document.
- Response:
- 200 OK: Returns a success message if the document is deleted.
- 404 Not Found: If the document with the specified ID is not found.
- 500 Internal Server Error: If an error occurs during the deletion process.
These routes provide various functionalities for managing documents based on the specified API version. Make sure to use the correct version in the URL to access the desired functionality.
- Install dependencies:
npm install
- Start the server:
npm start
Make sure to set the apiVersion
in api.config.js
to the desired version ('v1' or 'v2') to let the API know which version to use.
Feel free to explore other routes and functionalities of the API based on your specific use case.
For more details, refer to the source code and comments in the provided files.