RestfulApi
Full CRUD operations for a model.
- Overview
- model_class
- writeable_column_names
- readable_column_names
- searchable_column_names
- sortable_column_names
- default_sort_column_name
- read_only
- create_endpoint
- delete_endpoint
- update_endpoint
- get_endpoint
- list_endpoint
- create_request_methods
- update_request_methods
- delete_request_methods
- get_request_methods
- list_request_methods
- id_column_name
- group_by_column_name
- input_validation_callable
- include_routing_data_in_request_data
- url
- default_sort_direction
- default_limit
- maximum_limit
- request_methods
- response_headers
- output_map
- output_schema
- column_overrides
- internal_casing
- external_casing
- security_headers
- description
- authentication
- authorization
Overview
This endpoint group sets up all five standard endpoints to manage a model:
- Create
- Update
- Delete
- Get
- List
As such, you can set any option for all of the above endpoints. All five endpoints are enabled by default but can be turned off individually. It’s important to understand that the actual API behavior is controlled by other endoints. This endpoint group creates them and routes requests to them. So, to fully understand the behavior of the subsequent Restful API, you have to consult the documentation for the endpoints themselves.
For routing purposes, the create and list endpoints are reachable via the URL specified for this endpoint group and are separated by request method (POST for create by default, GET for list). The update, delete, and get endoints all expect the id to be appended to the base URL, and then are separated by request method (PATCH for update, DELETE for delete, and GET for get). See the example app and calls below:
import clearskies
from clearskies.validators import Required, Unique
from clearskies import columns
class User(clearskies.Model):
id_column_name = "id"
backend = clearskies.backends.MemoryBackend()
id = columns.Uuid()
name = columns.String(validators=[Required()])
username = columns.String(
validators=[
Required(),
Unique(),
]
)
age = columns.Integer(validators=[Required()])
created_at = columns.Created()
updated_at = columns.Updated()
wsgi = clearskies.contexts.WsgiRef(
clearskies.endpoints.RestfulApi(
url="users",
model_class=User,
readable_column_names=["id", "name", "username", "age", "created_at", "updated_at"],
writeable_column_names=["name", "username", "age"],
sortable_column_names=["id", "name", "username", "age", "created_at", "updated_at"],
searchable_column_names=["id", "name", "username", "age", "created_at", "updated_at"],
default_sort_column_name="name",
)
)
wsgi()
Which spins up a fully functional API. In the below usage examples we create two users, fetch one of them, update a user, delete the other, and then list all users.
$ curl 'http://localhost:8080/users' -d '{"name":"Bob", "username": "bob", "age": 25}' | jq
{
"status": "success",
"error": "",
"data": {
"id": "8bd9c03f-bb0c-41bd-afbc-f9526ded88f4",
"name": "Bob",
"username": "bob",
"age": 25,
"created_at": "2025-06-10T12:39:35+00:00",
"updated_at": "2025-06-10T12:39:35+00:00"
},
"pagination": {},
"input_errors": {}
}
$ curl 'http://localhost:8080/users' -d '{"name":"Alice", "username": "alice", "age": 22}' | jq
{
"status": "success",
"error": "",
"data": {
"id": "16d483c6-0eb1-4104-b07b-32f3d736223f",
"name": "Alice",
"username": "alice",
"age": 22,
"created_at": "2025-06-10T12:42:59+00:00",
"updated_at": "2025-06-10T12:42:59+00:00"
},
"pagination": {},
"input_errors": {}
}
$ curl 'http://localhost:8080/users/8bd9c03f-bb0c-41bd-afbc-f9526ded88f4' | jq
{
"status": "success",
"error": "",
"data": {
"id": "8bd9c03f-bb0c-41bd-afbc-f9526ded88f4",
"name": "Bob",
"username": "bob",
"age": 25,
"created_at": "2025-06-10T12:39:35+00:00",
"updated_at": "2025-06-10T12:39:35+00:00"
},
"pagination": {},
"input_errors": {}
}
$ curl 'http://localhost:8080/users/16d483c6-0eb1-4104-b07b-32f3d736223f' -d '{"name":"Alice Smith", "age": 23}' -X PATCH | jq
{
"status": "success",
"error": "",
"data": {
"id": "16d483c6-0eb1-4104-b07b-32f3d736223f",
"name": "Alice Smith",
"username": "alice",
"age": 23,
"created_at": "2025-06-10T12:42:59+00:00",
"updated_at": "2025-06-10T12:45:01+00:00"
},
"pagination": {},
"input_errors": {}
}
$ curl 'http://localhost:8080/users/8bd9c03f-bb0c-41bd-afbc-f9526ded88f4' -X DELETE | jq
{
"status": "success",
"error": "",
"data": {},
"pagination": {},
"input_errors": {}
}
$ curl 'http://localhost:8080/users/' | jq
{
"status": "success",
"error": "",
"data": [
{
"id": "16d483c6-0eb1-4104-b07b-32f3d736223f",
"name": "Alice Smith",
"username": "alice",
"age": 23,
"created_at": "2025-06-10T12:42:59+00:00",
"updated_at": "2025-06-10T12:45:01+00:00"
}
],
"pagination": {
"number_results": 1,
"limit": 50,
"next_page": {}
},
"input_errors": {}
}
model_class
Required
writeable_column_names
Required
readable_column_names
Required
searchable_column_names
Required
sortable_column_names
Required
default_sort_column_name
Required
read_only
Optional
create_endpoint
Optional
The endpoint class to use for managing the create operation.
This defaults to clearskies.endpoints.Create
. To disable the create operation all together, set this to None.
delete_endpoint
Optional
The endpoint class to use for managing the delete operation.
This defaults to clearskies.endpoints.Delete
. To disable the delete operation all together, set this to None.
update_endpoint
Optional
The endpoint class to use for managing the update operation.
This defaults to clearskies.endpoints.Update
. To disable the update operation all together, set this to None.
get_endpoint
Optional
The endpoint class to use to fetch individual records.
This defaults to clearskies.endpoints.Get
. To disable the get operation all together, set this to None.
list_endpoint
Optional
The endpoint class to use to list records.
This defaults to clearskies.endpoints.SimpleSearch
. To disable the list operation all together, set this to None.
create_request_methods
Optional
The request method(s) to use to route to the create operation. Default is [“POST”].
update_request_methods
Optional
The request method(s) to use to route to the update operation. Default is [“PATCH”].
delete_request_methods
Optional
The request method(s) to use to route to the delete operation. Default is [“DELETE”].
get_request_methods
Optional
The request method(s) to use to route to the get operation. Default is [“GET”].
list_request_methods
Optional
The request method(s) to use to route to the create operation. Default is [“GET”].
id_column_name
Optional
The request method(s) to use to route to the create operation. Default is [“POST”].
group_by_column_name
Optional
input_validation_callable
Optional
include_routing_data_in_request_data
Optional
url
Optional
The base URL to be used for all the endpoints.
default_sort_direction
Optional
default_limit
Optional
maximum_limit
Optional
request_methods
Optional
response_headers
Optional
output_map
Optional
output_schema
Optional
column_overrides
Optional
internal_casing
Optional
“snake_case”
external_casing
Optional
security_headers
Optional
description
Optional
authentication
Optional
authorization
Optional