1.3.6 โ€ข Published 4 months ago

localbased v1.3.6

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

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": "owoade@once.com",
      "password": "manager"
    }
  • Sample Response

    {
        "status": "success",
        "response": {
            "collectionName": "users",
            "data": {
                "_id": "51130271-1839-492b-b50b-1cca2ff19aa2",
                "name": "owoade anuoluwapo",
                "email": "owoade@once.com",
                "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:

ParameterTypeDescription
pagenumberThis enables pagination of data, facilitating the retrieval of specific subsets for more efficient handling of large datasets. The default value is 1.
limitnumberThis refers to the amount of to be returned per request. The default value is 50.
orderstringThis 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:

ParameterTypeDescription
idstringThis 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

1.3.6

4 months ago

1.3.5

4 months ago

1.3.4

4 months ago

1.3.3

4 months ago

1.2.0

4 months ago

1.2.8

4 months ago

1.1.9

4 months ago

1.2.7

4 months ago

1.1.8

4 months ago

1.2.6

4 months ago

1.1.7

4 months ago

1.2.5

4 months ago

1.2.4

4 months ago

1.3.2

4 months ago

1.2.3

4 months ago

1.3.1

4 months ago

1.2.2

4 months ago

1.3.0

4 months ago

1.2.1

4 months ago

1.2.9

4 months ago

1.1.6

10 months ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago