Endpoints
Endpoints define your API routes. They can use handlers for custom logic or leverage automatic CRUD operations from entities.
Basic Endpoint Definition
endpoints:
- path: /todos
method: GET
handler: handlers/listTodos
response:
type: TodoArrayEndpoint Methods
Yama supports all HTTP methods:
endpoints:
- path: /todos
method: GET # Retrieve data
handler: handlers/listTodos
- path: /todos
method: POST # Create data
handler: handlers/createTodo
- path: /todos/:id
method: PUT # Full update
handler: handlers/updateTodo
- path: /todos/:id
method: PATCH # Partial update
handler: handlers/patchTodo
- path: /todos/:id
method: DELETE # Delete data
handler: handlers/deleteTodoPath Parameters
Use :param syntax for dynamic routes:
endpoints:
- path: /users/:id
method: GET
params:
id:
type: string
required: true
handler: handlers/getUserQuery Parameters
Define query string parameters:
endpoints:
- path: /products
method: GET
query:
category:
type: string
required: false
limit:
type: number
default: 10
offset:
type: number
default: 0
handler: handlers/listProductsRequest Body
Define request body schemas:
endpoints:
- path: /todos
method: POST
body:
type: object
properties:
title:
type: string
completed:
type: boolean
handler: handlers/createTodoOr reference a schema:
endpoints:
- path: /todos
method: POST
body:
$ref: "#/schemas/Todo"
handler: handlers/createTodoResponse Types
Define response schemas:
endpoints:
- path: /todos
method: GET
response:
type: array
items:
$ref: "#/schemas/Todo"Authentication
Protect endpoints with authentication:
endpoints:
- path: /admin/users
method: GET
auth:
required: true
roles: ["admin"]
handler: handlers/listUsersHandler Types
Custom Handler
Use a TypeScript handler file:
endpoints:
- path: /custom
method: GET
handler: handlers/myHandlerQuery Handler
Query entities directly from config:
endpoints:
- path: /products/search
method: GET
handler:
type: query
entity: Product
filters:
- field: name
operator: ilike
param: query.search
query:
search:
type: string
response:
type: ProductArrayNext Steps
- Learn about Handlers - Implementing business logic
- See Guides: Handlers - Advanced handler patterns
- Check API Reference: Configuration - Complete endpoint options
Last updated on