API Generation
Drafta automatically generates both REST and GraphQL APIs based on the defined schema. This allows users to interact with their data effortlessly without manually implementing an API.
API Generation Process
When a schema is defined, Drafta processes it to create:
- REST API: Standard endpoints for retrieving data.
- GraphQL API: A flexible query interface for fetching data.
Example Schema:
user:
id: string @id
name: string
email: string
age: number
REST API
Drafta exposes RESTful endpoints based on schema definitions. The endpoint path matches the table name.
Example Endpoints for user
:
Method | Endpoint | Description |
---|---|---|
GET | /user | Fetch all users |
GET | /user?offset={offset}&limit={limit} | Fetch users with pagination |
GET | /user/{id} | Fetch a single user |
Query Parameters for GET /user
:
offset
(optional, integer) – The number of records to skip. Default is0
.limit
(optional, integer) – The maximum number of records to return. Default is10
.
Example Request (GET /user
):
[
{
"id": "1a2b3c",
"name": "Alice Johnson",
"email": "alice.johnson@example.com",
"age": 30
}
]
GraphQL API
Drafta also generates a GraphQL API, allowing for more flexible queries.
Example Query:
query {
user {
id
name
email
}
}
Example Query (With Pagination - offset
& limit
):
query {
user(offset: 10, limit: 5) {
id
name
email
}
}
Query Parameters:
offset
(optional, integer) – The number of records to skip. Default is0
.limit
(optional, integer) – The maximum number of records to return. Default is10
.
Example Response:
{
"data": {
"user": [
{
"id": "1a2b3c",
"name": "Alice Johnson",
"email": "alice.johnson@example.com"
}
]
}
}
Authentication
By default, API access is secured using API Keys. Users must include an API Key in their requests to authenticate.
GraphQL Explorer
Drafta provides an interactive GraphQL Explorer to help users test queries and view data structures easily. This tool enables intuitive API interaction without needing external tools.
Future Enhancements
Users can extend API functionality by defining custom endpoints for specific business logic.
At present, Drafta supports only data retrieval via REST and GraphQL. Future updates will introduce the ability to modify data through REST and GraphQL, enabling full data management capabilities.