Configurable HTTP client with automatic API method generation. More...
| Import Statement: | import Clayground.Network |
ClayHttpClient provides a declarative way to define REST API endpoints and generates callable methods automatically. It supports Bearer token, HTTP basic and API key authentication and handles both GET and POST requests.
Example usage:
import Clayground.Network ClayHttpClient { id: apiClient baseUrl: "https://api.example.com" endpoints: { "getUser": "GET users/{userId}", "createPost": "POST posts {postData}" } bearerToken: "your-api-token" onReply: (requestId, code, response) => { console.log("Success:", JSON.parse(response)) } onError: (requestId, code, error) => { console.error("Error:", error) } Component.onCompleted: { api.getUser(123) api.createPost({title: "Hello", content: "World"}) } }
Base URL for all API requests.
Object defining API endpoints. Format: "{HTTP_METHOD} {urlWithParams} [{bodyName}]"
Generated API methods object.
Bearer token for authentication. Takes precedence over basicAuthUser.
User name for HTTP basic authentication.
Password for HTTP basic authentication.
API key, sent in its own header and combinable with the other schemes.
Name of the header carrying apiKey, "X-API-Key" by default.
Every credential value can be given literally, as "env.<VARIABLE>" or as "file://<path>".
Emitted when a request completes successfully.
Emitted when a request fails.