Jdbase Docs

JDbase Documentation

This document provides an overview of the JDbase API developed to interact with databases and manage users via HTTP requests.

Table of Contents

  • Introduction

  • API Endpoints

  • /api

  • /users

Introduction

The JDBase API is designed to facilitate database operations and user management through HTTP requests. It offers endpoints for executing CRUD (Create, Read, Update, Delete) operations on databases, as well as for creating and managing users.

API Endpoints

/api Endpoint

POST /api

This endpoint is used for executing CRUD operations on databases. It requires an API key provided in the request header for authentication and authorization.

  • Type: POST

  • Request Headers:

  • api_key: The API key for authentication.

  • Request Body:

  • db: The name of the database.

  • query: The query to be executed.

  • type: The type of operation (create, read, update, delete, match).

  • update_query (optional): The query for updating records (required for update operation).

  • Response:

  • Success: JSON response with the result of the operation and HTTP status code 200.

  • Error: JSON response with error message and corresponding HTTP status code (401, 403, 400, 404, 500).

Supported Operations:

  • Create: Add new records to the database.

  • Read: Retrieve records from the database.

  • Update: Modify existing records in the database.

  • Delete: Remove records from the database.

  • Match: Check if records match specified criteria.

POST /users

This endpoint is used for creating users with specific permissions. It also requires an API key provided in the request header for authentication and authorization.

  • Type: POST

  • Request Headers:

  • api_key: The API key for authentication.

  • Request Body:

  • name: The name of the user.

  • permission: The permissions assigned to the user (create, read, update, delete).

  • Response:

  • Success: JSON response with a message confirming user creation and the generated API key, along with HTTP status code 200.

  • Error: JSON response with error message and corresponding HTTP status code (401, 403, 400).

Supported Operations

  • Create: Add new records to the database.

  • Read: Retrieve records from the database.

  • Update: Modify existing records in the database.

  • Delete: Remove records from the database.

  • Match: Check if records match specified criteria.

Example :

Default api key is "adminkey" you can change this editng config/apis.json

Create:

import requests
url = "http://127.0.0.1:5000/api"
payload = {
    "db": "db1",
    "type": "create",
    "query": {
        "name": "Rakib Hossain",
        "Skill": "Python"
    }
}
headers = {"api_key": "adminkey"}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

Read:

import requests

url = "http://127.0.0.1:5000/api"

payload = {
    "db": "db1",
    "type": "read",
    "query": {
        "Skill": "Python"
    }
}
headers = {"api_key": "adminkey"}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

Update:

import requests

url = "http://127.0.0.1:5000/api"

payload = {
    "db": "db1",
    "type": "update",
    "query": {
        "Skill": "Python"
    },
    "update_query":{
        "Skill":"Python_Api"
    }
}
headers = {"api_key": "adminkey"}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

Delete:

import requests

url = "http://127.0.0.1:5000/api"

payload = {
    "db": "db1",
    "type": "Delete",
    "query": {
    "Skill": "PHP"
    }
}
headers = {"api_key": "adminkey"}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

Match:

import requests

url = "http://127.0.0.1:5000/api"

payload = {
    "db": "db1",
    "type": "match",
    "query": {
    "email":"user@jdmail.com",
    "password":"user@password"
    }
}
headers = {"api_key": "adminkey"}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

Create_user:

import requests

url = "http://127.0.0.1:5000/user"

payload = {
    "name": "Developer",
    "permission":["read","create","update","delete"]
}
headers = {"api_key": "adminkey"}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

Create Database:

import requests

url = "http://127.0.0.1:5000/api"

payload = {
    "db": "db1",
    "type": "create_db",
    "query": {
    "name":"user"
    }
}
headers = {"api_key": "adminkey"}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

For any other unexpected errors, the API returns a generic "Internal Error" message with HTTP status code 500.

Happy Development

Last updated