Endpoint

Endpoints handle HTTP requests with type-safe request and response contracts.

Including Endpoint

struct MyEndpoint
  include Azu::Endpoint(RequestType, ResponseType)
end

Type Parameters:

  • RequestType - Request contract type (must include Azu::Request)

  • ResponseType - Response type (must include Azu::Response)

HTTP Method Macros

get

Define a GET endpoint.

get "/path"
get "/users/:id"
get "/search"

post

Define a POST endpoint.

put

Define a PUT endpoint.

patch

Define a PATCH endpoint.

delete

Define a DELETE endpoint.

options

Define an OPTIONS endpoint.

Define a HEAD endpoint.

Instance Methods

call

Handle the request. Must be implemented.

Returns: ResponseType

params

Access route and query parameters.

Returns: Hash(String, String)

headers

Access request headers.

Returns: HTTP::Headers

context

Access the full HTTP context.

Returns: HTTP::Server::Context

request

Access the HTTP request.

Returns: HTTP::Request

response

Access the HTTP response.

Returns: HTTP::Server::Response

status

Set the response status code.

Parameters:

  • code : Int32 - HTTP status code

Request Access

Access the typed request via generated method:

Method name is derived from request type: CreateUserRequestcreate_user_request

Response Helpers

json

Return JSON response.

text

Return plain text response.

html

Return HTML response.

redirect_to

Redirect to another URL.

Parameters:

  • url : String - Redirect URL

  • status : Int32 = 302 - HTTP status code

Route Parameters

Path Parameters

Wildcard Parameters

Complete Example

See Also

Last updated

Was this helpful?