API¶
The current Loom73 API is a small, explicit, read-only JSON layer.
It demonstrates how an application can expose selected resources without serializing complete models or database tables automatically.
Current endpoints¶
Both current user endpoints require an authenticated Loom73 session.
User collection¶
Successful response:
One user¶
Successful response:
The concrete model selects the exposed fields. Password hashes, salts, email addresses and recovery values are not included.
Error format¶
API errors use:
Current codes include:
Corresponding HTTP status codes include:
A method error also returns:
Read-only guard¶
Each endpoint must apply the GET guard explicitly:
Other methods receive:
The read-only rule is a controller convention enforced by ApiCtrl::requireGet(). Adding a new endpoint requires adding the guard to that endpoint.
Creating an endpoint¶
Write an explicit model query:
public function apiList(): QueryResult
{
$sql = '
SELECT
article.slug,
article.title
FROM article
WHERE article.status = :status
ORDER BY article.title ASC
';
return $this->query($sql, [
'status' => 2,
]);
}
Then expose it from the API controller:
public function articles(?string $slug = null): void
{
$this->requireAuth();
if (!$this->requireGet()):
return;
endif;
$Articles = new Article();
if ($slug === null):
$result = $Articles->apiList();
if ($result->fails()):
$this->jsonError(
code: 'query_failed',
message: 'Unable to retrieve articles.',
status: 500
);
return;
endif;
$this->json([
'data' => $result->all(),
]);
return;
endif;
// Retrieve and return one article.
}
Expose only the fields required by the API contract.
Public and protected endpoints¶
The current user endpoints call:
Without an authenticated session, the base guard redirects to /user/login. The unauthenticated response is therefore currently an HTML redirect rather than a JSON 401 error.
A public endpoint can omit that guard deliberately.
Session protection, public access and ability requirements must be visible in the endpoint method.
JSON responses¶
ApiCtrl::json():
- disables template rendering;
- sets the HTTP status;
- sends
application/json; charset=utf-8; - encodes without escaping Unicode or slashes.
Example:
Errors use:
Current boundaries¶
The API does not currently provide:
bearer-token authentication
write operations
automatic model serialization
pagination metadata
content negotiation
API version routing
rate limiting
CORS configuration
JSON validation errors
an OpenAPI document
Machine-to-machine authentication and write operations remain future work.
The governing rule is: