localbased
v1.3.6
Published
Localbased is an intuitive no-code tool designed to assist developers, particularly frontend engineers, in quickly setting up a REST API for communicating with databases on their local machines. It aims to simplify the process of creating a backend server
Downloads
52
Readme
localbased
Localbased is an intuitive no-code tool designed to assist developers, particularly frontend engineers, in quickly setting up a REST API for communicating with databases on their local machines. It aims to simplify the process of creating a backend server and accessing dynamic data, enabling frontend developers to create full-stack side projects without the need to worry about building a REST API or handling database interactions.
Installation
npm i -g localbased
Initialization
In your current working directory run
localbased start --port [port]
this command starts the server on the specified port else the server runs on a default port of 2048
.
E.g
localbased start --port 4000
this command starts the server on the specified port 4000
localbased start
this command starts the server on the default port 2048
Endpoints
1. Create
Description: Creates a record in the database.
Endpoint:
/:collectionName/create
Method: POST
Request Body:
{ ...data }
Sample Request: POST /users/create
{ "name": "owoade anuoluwapo", "email": "[email protected]", "password": "manager" }
Sample Response
{ "status": "success", "response": { "collectionName": "users", "data": { "_id": "51130271-1839-492b-b50b-1cca2ff19aa2", "name": "owoade anuoluwapo", "email": "[email protected]", "password": "manager", "timestamps": { "createdAt": "2024-01-15T00:22:49.430Z", "updatedAt": "2024-01-15T00:22:49.430Z" } } } }
2. Get All
- Description: Retrieves all records in a collection.
- Endpoint:
/:collectionName/get/all
- Method: GET
- Query parameters:
| Parameter | Type | Description |
|---------------------|----------|------------------------------------------------------------------------------------------------------|
| page | number | This enables pagination of data, facilitating the retrieval of specific subsets for more efficient handling of large datasets. The default value is 1. |
| limit | number | This refers to the amount of to be returned per request. The default value is 50. |
| order | string | This is the order in which the result will be returned and can either be of value a
which denotes ascending order or d
descending order. The default value is a
|
Sample Request: GET /users/get/all?order=a&limit=3&page=1
Sample Response
{ "status": "success", "response": { "collectionName": "users", "count": 359, "data": [ { "_id": "cb405221-2266-4d87-9939-ded1fbd3eab7", "username": "Mary", "password": "kemi", "timestamps": { "createdAt": 1705267312054 } }, { "_id": "a4bd932a-1f8e-4ff8-84c5-95e800326e1c", "username": "Mary", "password": "kemi", "timestamps": { "createdAt": 1705267325168 } } ] } }
3. Get one
- Description: Gets one record from the database.
- Endpoint:
/:collectionName/get/single/:id
- Method: GET
- Route parameters:
| Parameter | Type | Description | |---------------------|----------|------------------------------------------------------------------------------------------------------| | id | string | This is the of the record to be fetched. |
Sample Request: GET /user/get/single/cc6443a8-7633-45d4-b6a1-4335c3c59f81
Sample Response
{ "status": "success", "response": { "collectionName": "users", "data": { "_id": "cc6443a8-7633-45d4-b6a1-4335c3c59f81", "name": "owoade anuoluwapo", "password": "manager", "timestamps": { "createdAt": "2024-01-14T22:55:53.010Z", "updatedAt": "2024-01-14T23:16:22.222Z" }, "is_admin": true } } }
4. Update
Description: Updates a record in the database.
Endpoint:
/:collectionName/update/:id
Method: PATCH
Request Body:
{ "update": { ...updates } }
Sample Request: PATCH /user/update/cc6443a8-7633-45d4-b6a1-4335c3c59f81
{ "update": { "is_admin": true } }
Sample Response
{ "status": "success", "response": { "collectionName": "users", "data": { "_id": "cc6443a8-7633-45d4-b6a1-4335c3c59f81", "name": "owoade anuoluwapo", "password": "manager", "timestamps": { "createdAt": "2024-01-14T22:55:53.010Z", "updatedAt": "2024-01-14T23:16:22.222Z" }, "is_admin": true } } }
5. Delete
Description: Deletes a record from the database.
Endpoint:
/:collectionName/delete/:id
Method: DELETE
Sample Request: DELETE /user/delete/cc6443a8-7633-45d4-b6a1-4335c3c59f81
{ "update": { "is_admin": true } }
Sample Response
{ "status": "success", "response": {} }
Error Response
An error response can be returned for a number of reasons, below is an example of an error response that can be returned. Note that all error response structure are the same.
{
"status": "error",
"response": false,
"reason": "Document not found"
}
...Start Building 🚀🚀
Created with 🧡 by Owoade