Optimize Endpoints
Response Caching
struct ProductsEndpoint
include Azu::Endpoint(EmptyRequest, ProductsResponse)
get "/products"
CACHE_TTL = 5.minutes
def call : ProductsResponse
cache_key = "products:#{cache_params}"
cached = Azu.cache.get(cache_key)
return ProductsResponse.from_json(cached) if cached
products = Product.all
response = ProductsResponse.new(products)
Azu.cache.set(cache_key, response.to_json, expires_in: CACHE_TTL)
response
end
private def cache_params
"page=#{params["page"]? || 1}&limit=#{params["limit"]? || 20}"
end
endHTTP Caching Headers
Pagination
Selective Field Loading
Eager Loading
Parallel Processing
Compression
Connection Keep-Alive
Response Streaming
Async External Calls
Request Timeouts
Benchmark Endpoints
See Also
Last updated
Was this helpful?
