> For the complete documentation index, see [llms.txt](https://rakibmia7254.gitbook.io/jdbase/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rakibmia7254.gitbook.io/jdbase/jdbase-docs.md).

# Jdbase Docs

### JDbase Documentation <a href="#jdbase-documentation" id="jdbase-documentation"></a>

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

### Table of Contents <a href="#table-of-contents" id="table-of-contents"></a>

* [Introduction](broken://pages/lOlBb2ZjDGBfSYZ2jIvs)
* [API Endpoints](broken://pages/lOlBb2ZjDGBfSYZ2jIvs)
* [`/api`](broken://pages/lOlBb2ZjDGBfSYZ2jIvs)
* [`/users`](broken://pages/lOlBb2ZjDGBfSYZ2jIvs)

### Introduction <a href="#introduction" id="introduction"></a>

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 <a href="#api-endpoints" id="api-endpoints"></a>

#### `/api` Endpoint <a href="#api-endpoint" id="api-endpoint"></a>

**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` <a href="#post-users" id="post-users"></a>

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 <a href="#supported-operations" id="supported-operations"></a>

* **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:*

```python
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:*

```python
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:*

```python
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:*

```python
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:*

```python
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:*

```python
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:*

```python
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.

#### [Contribute ON Github](https://github.com/rakibmia7254/JDbase) <a href="#contribute-on-github" id="contribute-on-github"></a>

*Happy Development*
