Module: Respondo::ControllerHelpers
- Defined in:
- lib/respondo/controller_helpers.rb
Overview
Mixed into Rails controllers to provide render_success and render_error.
Success helpers (2xx):
render_success, render_ok, render_created, render_accepted,
render_non_authoritative, render_no_content, render_reset_content,
render_partial_content, render_multi_status, render_already_reported,
render_im_used
Informational helpers (1xx):
render_continue, render_switching_protocols, render_processing,
render_early_hints
Redirect helpers (3xx):
render_multiple_choices, render_moved_permanently, render_found,
render_see_other, render_not_modified, render_temporary_redirect,
render_permanent_redirect
Client error helpers (4xx):
render_bad_request, render_unauthorized, render_payment_required,
render_forbidden, render_not_found, render_method_not_allowed,
render_not_acceptable, render_proxy_auth_required, render_request_timeout,
render_conflict, render_gone, render_length_required,
render_precondition_failed, render_payload_too_large, render_uri_too_long,
render_unsupported_media_type, render_range_not_satisfiable,
render_expectation_failed, render_im_a_teapot, render_misdirected_request,
render_unprocessable, render_locked, render_failed_dependency,
render_too_early, render_upgrade_required, render_precondition_required,
render_too_many_requests, render_request_header_fields_too_large,
render_unavailable_for_legal_reasons
Server error helpers (5xx):
render_server_error, render_not_implemented, render_bad_gateway,
render_service_unavailable, render_gateway_timeout,
render_http_version_not_supported, render_variant_also_negotiates,
render_insufficient_storage, render_loop_detected, render_not_extended,
render_network_authentication_required
Instance Method Summary collapse
-
#render_accepted(data: nil, message: "Request accepted and is being processed", meta: {}, pagination: nil) ⇒ Object
202 Accepted — async jobs, background processing.
-
#render_already_reported(data: nil, message: "Already reported", meta: {}, pagination: nil) ⇒ Object
208 Already Reported (WebDAV) — members already enumerated.
-
#render_bad_gateway(message: "Bad gateway — upstream service error", errors: nil, meta: {}) ⇒ Object
502 Bad Gateway — upstream service failed.
-
#render_bad_request(message: "Bad request", errors: nil, meta: {}) ⇒ Object
400 Bad Request — malformed request, invalid params.
-
#render_conflict(message: "Resource conflict", errors: nil, meta: {}) ⇒ Object
409 Conflict — duplicate record, state conflict.
-
#render_continue(message: "Continue", meta: {}) ⇒ Object
100 Continue.
-
#render_created(data: nil, message: "Created successfully", meta: {}, pagination: nil) ⇒ Object
201 Created.
-
#render_early_hints(message: "Early hints", meta: {}) ⇒ Object
103 Early Hints.
-
#render_error(message: nil, errors: nil, code: nil, meta: {}, status: :unprocessable_entity) ⇒ Object
Render an error JSON response.
-
#render_expectation_failed(message: "Expectation failed", errors: nil, meta: {}) ⇒ Object
417 Expectation Failed — Expect header cannot be met.
-
#render_failed_dependency(message: "Failed dependency", errors: nil, meta: {}) ⇒ Object
424 Failed Dependency (WebDAV) — previous request failed.
-
#render_forbidden(message: "You do not have permission to perform this action", errors: nil, meta: {}) ⇒ Object
403 Forbidden — authenticated but not authorized.
-
#render_found(message: "Resource temporarily located elsewhere", meta: {}, pagination: nil) ⇒ Object
302 Found (temporary redirect).
-
#render_gateway_timeout(message: "Gateway timeout — upstream service did not respond", errors: nil, meta: {}) ⇒ Object
504 Gateway Timeout — upstream service timed out.
-
#render_gone(message: "Resource no longer available", errors: nil, meta: {}) ⇒ Object
410 Gone — resource permanently deleted.
-
#render_http_version_not_supported(message: "HTTP version not supported", errors: nil, meta: {}) ⇒ Object
505 HTTP Version Not Supported.
-
#render_im_a_teapot(message: "I'm a teapot", errors: nil, meta: {}) ⇒ Object
418 I’m a Teapot — RFC 2324.
-
#render_im_used(data: nil, message: "IM used", meta: {}, pagination: nil) ⇒ Object
226 IM Used — instance manipulations applied.
-
#render_insufficient_storage(message: "Insufficient storage", errors: nil, meta: {}) ⇒ Object
507 Insufficient Storage (WebDAV).
-
#render_length_required(message: "Content-Length header required", errors: nil, meta: {}) ⇒ Object
411 Length Required — Content-Length header missing.
-
#render_locked(message: "Resource is locked", errors: nil, meta: {}) ⇒ Object
423 Locked — resource is locked.
-
#render_loop_detected(message: "Loop detected", errors: nil, meta: {}) ⇒ Object
508 Loop Detected (WebDAV).
-
#render_method_not_allowed(message: "HTTP method not allowed", errors: nil, meta: {}) ⇒ Object
405 Method Not Allowed.
-
#render_misdirected_request(message: "Misdirected request", errors: nil, meta: {}) ⇒ Object
421 Misdirected Request — request sent to wrong server.
-
#render_moved_permanently(message: "Resource has moved permanently", meta: {}, pagination: nil) ⇒ Object
301 Moved Permanently.
-
#render_multi_status(data: nil, message: "Multi-status response", meta: {}, pagination: nil) ⇒ Object
207 Multi-Status (WebDAV) — batch operations with mixed results.
-
#render_multiple_choices(data: nil, message: "Multiple choices available", meta: {}, pagination: nil) ⇒ Object
300 Multiple Choices.
-
#render_network_authentication_required(message: "Network authentication required", errors: nil, meta: {}) ⇒ Object
511 Network Authentication Required — must authenticate to access network.
-
#render_no_content(message: "Deleted successfully", meta: {}, pagination: nil) ⇒ Object
204 No Content — deletions, actions with no response body Note: we still return our standard JSON structure for consistency.
-
#render_non_authoritative(data: nil, message: "Non-authoritative information", meta: {}, pagination: nil) ⇒ Object
203 Non-Authoritative Information — response from a third-party cache/proxy.
-
#render_not_acceptable(message: "Requested format not acceptable", errors: nil, meta: {}) ⇒ Object
406 Not Acceptable — client Accept header can’t be satisfied.
-
#render_not_extended(message: "Not extended", errors: nil, meta: {}) ⇒ Object
510 Not Extended — further extensions needed.
-
#render_not_found(message: "Resource not found", errors: nil, meta: {}) ⇒ Object
404 Not Found.
-
#render_not_implemented(message: "This feature is not yet implemented", errors: nil, meta: {}) ⇒ Object
501 Not Implemented — feature not built yet.
-
#render_not_modified(message: "Resource not modified", meta: {}, pagination: nil) ⇒ Object
304 Not Modified — client cache is still valid.
-
#render_ok(data: nil, message: nil, meta: {}, pagination: nil) ⇒ Object
200 OK — alias for render_success with no pagination (single record).
-
#render_partial_content(data: nil, message: "Partial content returned", meta: {}, pagination: nil) ⇒ Object
206 Partial Content — chunked / range responses.
-
#render_payload_too_large(message: "Payload too large", errors: nil, meta: {}) ⇒ Object
413 Payload Too Large — request body exceeds server limit.
-
#render_payment_required(message: "Payment required to access this resource", errors: nil, meta: {}) ⇒ Object
402 Payment Required — paywalled features.
-
#render_permanent_redirect(message: "Permanent redirect", meta: {}, pagination: nil) ⇒ Object
308 Permanent Redirect — like 301 but method must not change.
-
#render_precondition_failed(message: "Precondition failed", errors: nil, meta: {}) ⇒ Object
412 Precondition Failed — conditional request failed.
-
#render_precondition_required(message: "Precondition required", errors: nil, meta: {}) ⇒ Object
428 Precondition Required — request must be conditional.
-
#render_processing(message: "Processing", meta: {}) ⇒ Object
102 Processing (WebDAV).
-
#render_proxy_auth_required(message: "Proxy authentication required", errors: nil, meta: {}) ⇒ Object
407 Proxy Authentication Required.
-
#render_range_not_satisfiable(message: "Range not satisfiable", errors: nil, meta: {}) ⇒ Object
416 Range Not Satisfiable — Range header cannot be fulfilled.
-
#render_request_header_fields_too_large(message: "Request header fields too large", errors: nil, meta: {}) ⇒ Object
431 Request Header Fields Too Large.
-
#render_request_timeout(message: "Request timed out", errors: nil, meta: {}) ⇒ Object
408 Request Timeout.
-
#render_reset_content(message: "Reset content", meta: {}, pagination: nil) ⇒ Object
205 Reset Content — tell the client to reset the document view.
-
#render_see_other(message: "See other resource", meta: {}, pagination: nil) ⇒ Object
303 See Other — redirect to another URI with GET.
-
#render_server_error(message: "An unexpected error occurred", errors: nil, meta: {}) ⇒ Object
500 Internal Server Error.
-
#render_service_unavailable(message: "Service temporarily unavailable", errors: nil, meta: {}) ⇒ Object
503 Service Unavailable — maintenance, overloaded.
-
#render_success(data: nil, message: nil, meta: {}, code: nil, pagination: nil, status: :ok) ⇒ Object
Render a successful JSON response.
-
#render_switching_protocols(message: "Switching protocols", meta: {}) ⇒ Object
101 Switching Protocols.
-
#render_temporary_redirect(message: "Temporary redirect", meta: {}, pagination: nil) ⇒ Object
307 Temporary Redirect — repeat request with same method to new URL.
-
#render_too_early(message: "Too early", errors: nil, meta: {}) ⇒ Object
425 Too Early — server unwilling to risk processing replayed request.
-
#render_too_many_requests(message: "Too many requests. Please slow down.", errors: nil, meta: {}) ⇒ Object
429 Too Many Requests — rate limiting.
-
#render_unauthorized(message: "Unauthorized", errors: nil, meta: {}) ⇒ Object
401 Unauthorized — not authenticated.
-
#render_unavailable_for_legal_reasons(message: "Unavailable for legal reasons", errors: nil, meta: {}) ⇒ Object
451 Unavailable for Legal Reasons — censored/DMCA etc.
-
#render_unprocessable(message: "Validation failed", errors: nil, meta: {}) ⇒ Object
422 Unprocessable Entity — validation errors (most common for APIs).
-
#render_unsupported_media_type(message: "Unsupported media type", errors: nil, meta: {}) ⇒ Object
415 Unsupported Media Type — wrong Content-Type header.
-
#render_upgrade_required(message: "Upgrade required", errors: nil, meta: {}) ⇒ Object
426 Upgrade Required — client must switch protocols.
-
#render_uri_too_long(message: "URI too long", errors: nil, meta: {}) ⇒ Object
414 URI Too Long — request URI exceeds server limit.
-
#render_variant_also_negotiates(message: "Variant also negotiates", errors: nil, meta: {}) ⇒ Object
506 Variant Also Negotiates — server configuration error.
Instance Method Details
#render_accepted(data: nil, message: "Request accepted and is being processed", meta: {}, pagination: nil) ⇒ Object
202 Accepted — async jobs, background processing
137 138 139 |
# File 'lib/respondo/controller_helpers.rb', line 137 def render_accepted(data: nil, message: "Request accepted and is being processed", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 202, status: :accepted) end |
#render_already_reported(data: nil, message: "Already reported", meta: {}, pagination: nil) ⇒ Object
208 Already Reported (WebDAV) — members already enumerated
168 169 170 |
# File 'lib/respondo/controller_helpers.rb', line 168 def render_already_reported(data: nil, message: "Already reported", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 208, status: :already_reported) end |
#render_bad_gateway(message: "Bad gateway — upstream service error", errors: nil, meta: {}) ⇒ Object
502 Bad Gateway — upstream service failed
381 382 383 |
# File 'lib/respondo/controller_helpers.rb', line 381 def render_bad_gateway(message: "Bad gateway — upstream service error", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 502, status: :bad_gateway) end |
#render_bad_request(message: "Bad request", errors: nil, meta: {}) ⇒ Object
400 Bad Request — malformed request, invalid params
222 223 224 |
# File 'lib/respondo/controller_helpers.rb', line 222 def render_bad_request(message: "Bad request", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 400, status: :bad_request) end |
#render_conflict(message: "Resource conflict", errors: nil, meta: {}) ⇒ Object
409 Conflict — duplicate record, state conflict
267 268 269 |
# File 'lib/respondo/controller_helpers.rb', line 267 def render_conflict(message: "Resource conflict", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 409, status: :conflict) end |
#render_continue(message: "Continue", meta: {}) ⇒ Object
100 Continue
103 104 105 |
# File 'lib/respondo/controller_helpers.rb', line 103 def render_continue(message: "Continue", meta: {}) render_success(data: nil, message: , meta: , code: 100, status: :continue) end |
#render_created(data: nil, message: "Created successfully", meta: {}, pagination: nil) ⇒ Object
201 Created
132 133 134 |
# File 'lib/respondo/controller_helpers.rb', line 132 def render_created(data: nil, message: "Created successfully", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 201, status: :created) end |
#render_early_hints(message: "Early hints", meta: {}) ⇒ Object
103 Early Hints
118 119 120 |
# File 'lib/respondo/controller_helpers.rb', line 118 def render_early_hints(message: "Early hints", meta: {}) render_success(data: nil, message: , meta: , code: 103, status: :early_hints) end |
#render_error(message: nil, errors: nil, code: nil, meta: {}, status: :unprocessable_entity) ⇒ Object
Render an error JSON response.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/respondo/controller_helpers.rb', line 79 def render_error(message: nil, errors: nil, code: nil, meta: {}, status: :unprocessable_entity) extracted_errors = extract_errors(errors) = code ? .merge(code: code, status: status) : payload = ResponseBuilder.new( success: false, data: nil, message: , meta: , errors: extracted_errors, request: try(:request) ).build render json: payload, status: status end |
#render_expectation_failed(message: "Expectation failed", errors: nil, meta: {}) ⇒ Object
417 Expectation Failed — Expect header cannot be met
307 308 309 |
# File 'lib/respondo/controller_helpers.rb', line 307 def render_expectation_failed(message: "Expectation failed", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 417, status: :expectation_failed) end |
#render_failed_dependency(message: "Failed dependency", errors: nil, meta: {}) ⇒ Object
424 Failed Dependency (WebDAV) — previous request failed
332 333 334 |
# File 'lib/respondo/controller_helpers.rb', line 332 def render_failed_dependency(message: "Failed dependency", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 424, status: :failed_dependency) end |
#render_forbidden(message: "You do not have permission to perform this action", errors: nil, meta: {}) ⇒ Object
403 Forbidden — authenticated but not authorized
237 238 239 |
# File 'lib/respondo/controller_helpers.rb', line 237 def render_forbidden(message: "You do not have permission to perform this action", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 403, status: :forbidden) end |
#render_found(message: "Resource temporarily located elsewhere", meta: {}, pagination: nil) ⇒ Object
302 Found (temporary redirect)
193 194 195 |
# File 'lib/respondo/controller_helpers.rb', line 193 def render_found(message: "Resource temporarily located elsewhere", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 302, status: :found) end |
#render_gateway_timeout(message: "Gateway timeout — upstream service did not respond", errors: nil, meta: {}) ⇒ Object
504 Gateway Timeout — upstream service timed out
391 392 393 |
# File 'lib/respondo/controller_helpers.rb', line 391 def render_gateway_timeout(message: "Gateway timeout — upstream service did not respond", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 504, status: :gateway_timeout) end |
#render_gone(message: "Resource no longer available", errors: nil, meta: {}) ⇒ Object
410 Gone — resource permanently deleted
272 273 274 |
# File 'lib/respondo/controller_helpers.rb', line 272 def render_gone(message: "Resource no longer available", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 410, status: :gone) end |
#render_http_version_not_supported(message: "HTTP version not supported", errors: nil, meta: {}) ⇒ Object
505 HTTP Version Not Supported
396 397 398 |
# File 'lib/respondo/controller_helpers.rb', line 396 def render_http_version_not_supported(message: "HTTP version not supported", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 505, status: :http_version_not_supported) end |
#render_im_a_teapot(message: "I'm a teapot", errors: nil, meta: {}) ⇒ Object
418 I’m a Teapot — RFC 2324
312 313 314 |
# File 'lib/respondo/controller_helpers.rb', line 312 def render_im_a_teapot(message: "I'm a teapot", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 418, status: :im_a_teapot) end |
#render_im_used(data: nil, message: "IM used", meta: {}, pagination: nil) ⇒ Object
226 IM Used — instance manipulations applied
173 174 175 |
# File 'lib/respondo/controller_helpers.rb', line 173 def render_im_used(data: nil, message: "IM used", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 226, status: :im_used) end |
#render_insufficient_storage(message: "Insufficient storage", errors: nil, meta: {}) ⇒ Object
507 Insufficient Storage (WebDAV)
406 407 408 |
# File 'lib/respondo/controller_helpers.rb', line 406 def render_insufficient_storage(message: "Insufficient storage", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 507, status: :insufficient_storage) end |
#render_length_required(message: "Content-Length header required", errors: nil, meta: {}) ⇒ Object
411 Length Required — Content-Length header missing
277 278 279 |
# File 'lib/respondo/controller_helpers.rb', line 277 def render_length_required(message: "Content-Length header required", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 411, status: :length_required) end |
#render_locked(message: "Resource is locked", errors: nil, meta: {}) ⇒ Object
423 Locked — resource is locked
327 328 329 |
# File 'lib/respondo/controller_helpers.rb', line 327 def render_locked(message: "Resource is locked", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 423, status: :locked) end |
#render_loop_detected(message: "Loop detected", errors: nil, meta: {}) ⇒ Object
508 Loop Detected (WebDAV)
411 412 413 |
# File 'lib/respondo/controller_helpers.rb', line 411 def render_loop_detected(message: "Loop detected", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 508, status: :loop_detected) end |
#render_method_not_allowed(message: "HTTP method not allowed", errors: nil, meta: {}) ⇒ Object
405 Method Not Allowed
247 248 249 |
# File 'lib/respondo/controller_helpers.rb', line 247 def render_method_not_allowed(message: "HTTP method not allowed", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 405, status: :method_not_allowed) end |
#render_misdirected_request(message: "Misdirected request", errors: nil, meta: {}) ⇒ Object
421 Misdirected Request — request sent to wrong server
317 318 319 |
# File 'lib/respondo/controller_helpers.rb', line 317 def render_misdirected_request(message: "Misdirected request", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 421, status: :misdirected_request) end |
#render_moved_permanently(message: "Resource has moved permanently", meta: {}, pagination: nil) ⇒ Object
301 Moved Permanently
188 189 190 |
# File 'lib/respondo/controller_helpers.rb', line 188 def render_moved_permanently(message: "Resource has moved permanently", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 301, status: :moved_permanently) end |
#render_multi_status(data: nil, message: "Multi-status response", meta: {}, pagination: nil) ⇒ Object
207 Multi-Status (WebDAV) — batch operations with mixed results
163 164 165 |
# File 'lib/respondo/controller_helpers.rb', line 163 def render_multi_status(data: nil, message: "Multi-status response", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 207, status: :multi_status) end |
#render_multiple_choices(data: nil, message: "Multiple choices available", meta: {}, pagination: nil) ⇒ Object
300 Multiple Choices
183 184 185 |
# File 'lib/respondo/controller_helpers.rb', line 183 def render_multiple_choices(data: nil, message: "Multiple choices available", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 300, status: :multiple_choices) end |
#render_network_authentication_required(message: "Network authentication required", errors: nil, meta: {}) ⇒ Object
511 Network Authentication Required — must authenticate to access network
421 422 423 |
# File 'lib/respondo/controller_helpers.rb', line 421 def render_network_authentication_required(message: "Network authentication required", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 511, status: :network_authentication_required) end |
#render_no_content(message: "Deleted successfully", meta: {}, pagination: nil) ⇒ Object
204 No Content — deletions, actions with no response body Note: we still return our standard JSON structure for consistency
148 149 150 |
# File 'lib/respondo/controller_helpers.rb', line 148 def render_no_content(message: "Deleted successfully", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 204, status: :no_content) end |
#render_non_authoritative(data: nil, message: "Non-authoritative information", meta: {}, pagination: nil) ⇒ Object
203 Non-Authoritative Information — response from a third-party cache/proxy
142 143 144 |
# File 'lib/respondo/controller_helpers.rb', line 142 def (data: nil, message: "Non-authoritative information", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 203, status: :non_authoritative_information) end |
#render_not_acceptable(message: "Requested format not acceptable", errors: nil, meta: {}) ⇒ Object
406 Not Acceptable — client Accept header can’t be satisfied
252 253 254 |
# File 'lib/respondo/controller_helpers.rb', line 252 def render_not_acceptable(message: "Requested format not acceptable", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 406, status: :not_acceptable) end |
#render_not_extended(message: "Not extended", errors: nil, meta: {}) ⇒ Object
510 Not Extended — further extensions needed
416 417 418 |
# File 'lib/respondo/controller_helpers.rb', line 416 def render_not_extended(message: "Not extended", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 510, status: :not_extended) end |
#render_not_found(message: "Resource not found", errors: nil, meta: {}) ⇒ Object
404 Not Found
242 243 244 |
# File 'lib/respondo/controller_helpers.rb', line 242 def render_not_found(message: "Resource not found", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 404, status: :not_found) end |
#render_not_implemented(message: "This feature is not yet implemented", errors: nil, meta: {}) ⇒ Object
501 Not Implemented — feature not built yet
376 377 378 |
# File 'lib/respondo/controller_helpers.rb', line 376 def render_not_implemented(message: "This feature is not yet implemented", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 501, status: :not_implemented) end |
#render_not_modified(message: "Resource not modified", meta: {}, pagination: nil) ⇒ Object
304 Not Modified — client cache is still valid
203 204 205 |
# File 'lib/respondo/controller_helpers.rb', line 203 def render_not_modified(message: "Resource not modified", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 304, status: :not_modified) end |
#render_ok(data: nil, message: nil, meta: {}, pagination: nil) ⇒ Object
200 OK — alias for render_success with no pagination (single record)
127 128 129 |
# File 'lib/respondo/controller_helpers.rb', line 127 def render_ok(data: nil, message: nil, meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 200, status: :ok) end |
#render_partial_content(data: nil, message: "Partial content returned", meta: {}, pagination: nil) ⇒ Object
206 Partial Content — chunked / range responses
158 159 160 |
# File 'lib/respondo/controller_helpers.rb', line 158 def render_partial_content(data: nil, message: "Partial content returned", meta: {}, pagination: nil) render_success(data: data, message: , meta: , pagination: pagination, code: 206, status: :partial_content) end |
#render_payload_too_large(message: "Payload too large", errors: nil, meta: {}) ⇒ Object
413 Payload Too Large — request body exceeds server limit
287 288 289 |
# File 'lib/respondo/controller_helpers.rb', line 287 def render_payload_too_large(message: "Payload too large", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 413, status: :payload_too_large) end |
#render_payment_required(message: "Payment required to access this resource", errors: nil, meta: {}) ⇒ Object
402 Payment Required — paywalled features
232 233 234 |
# File 'lib/respondo/controller_helpers.rb', line 232 def render_payment_required(message: "Payment required to access this resource", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 402, status: :payment_required) end |
#render_permanent_redirect(message: "Permanent redirect", meta: {}, pagination: nil) ⇒ Object
308 Permanent Redirect — like 301 but method must not change
213 214 215 |
# File 'lib/respondo/controller_helpers.rb', line 213 def render_permanent_redirect(message: "Permanent redirect", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 308, status: :permanent_redirect) end |
#render_precondition_failed(message: "Precondition failed", errors: nil, meta: {}) ⇒ Object
412 Precondition Failed — conditional request failed
282 283 284 |
# File 'lib/respondo/controller_helpers.rb', line 282 def render_precondition_failed(message: "Precondition failed", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 412, status: :precondition_failed) end |
#render_precondition_required(message: "Precondition required", errors: nil, meta: {}) ⇒ Object
428 Precondition Required — request must be conditional
347 348 349 |
# File 'lib/respondo/controller_helpers.rb', line 347 def render_precondition_required(message: "Precondition required", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 428, status: :precondition_required) end |
#render_processing(message: "Processing", meta: {}) ⇒ Object
102 Processing (WebDAV)
113 114 115 |
# File 'lib/respondo/controller_helpers.rb', line 113 def render_processing(message: "Processing", meta: {}) render_success(data: nil, message: , meta: , code: 102, status: :processing) end |
#render_proxy_auth_required(message: "Proxy authentication required", errors: nil, meta: {}) ⇒ Object
407 Proxy Authentication Required
257 258 259 |
# File 'lib/respondo/controller_helpers.rb', line 257 def render_proxy_auth_required(message: "Proxy authentication required", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 407, status: :proxy_authentication_required) end |
#render_range_not_satisfiable(message: "Range not satisfiable", errors: nil, meta: {}) ⇒ Object
416 Range Not Satisfiable — Range header cannot be fulfilled
302 303 304 |
# File 'lib/respondo/controller_helpers.rb', line 302 def render_range_not_satisfiable(message: "Range not satisfiable", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 416, status: :range_not_satisfiable) end |
#render_request_header_fields_too_large(message: "Request header fields too large", errors: nil, meta: {}) ⇒ Object
431 Request Header Fields Too Large
357 358 359 |
# File 'lib/respondo/controller_helpers.rb', line 357 def render_request_header_fields_too_large(message: "Request header fields too large", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 431, status: :request_header_fields_too_large) end |
#render_request_timeout(message: "Request timed out", errors: nil, meta: {}) ⇒ Object
408 Request Timeout
262 263 264 |
# File 'lib/respondo/controller_helpers.rb', line 262 def render_request_timeout(message: "Request timed out", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 408, status: :request_timeout) end |
#render_reset_content(message: "Reset content", meta: {}, pagination: nil) ⇒ Object
205 Reset Content — tell the client to reset the document view
153 154 155 |
# File 'lib/respondo/controller_helpers.rb', line 153 def render_reset_content(message: "Reset content", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 205, status: :reset_content) end |
#render_see_other(message: "See other resource", meta: {}, pagination: nil) ⇒ Object
303 See Other — redirect to another URI with GET
198 199 200 |
# File 'lib/respondo/controller_helpers.rb', line 198 def render_see_other(message: "See other resource", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 303, status: :see_other) end |
#render_server_error(message: "An unexpected error occurred", errors: nil, meta: {}) ⇒ Object
500 Internal Server Error
371 372 373 |
# File 'lib/respondo/controller_helpers.rb', line 371 def render_server_error(message: "An unexpected error occurred", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 500, status: :internal_server_error) end |
#render_service_unavailable(message: "Service temporarily unavailable", errors: nil, meta: {}) ⇒ Object
503 Service Unavailable — maintenance, overloaded
386 387 388 |
# File 'lib/respondo/controller_helpers.rb', line 386 def render_service_unavailable(message: "Service temporarily unavailable", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 503, status: :service_unavailable) end |
#render_success(data: nil, message: nil, meta: {}, code: nil, pagination: nil, status: :ok) ⇒ Object
Render a successful JSON response.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/respondo/controller_helpers.rb', line 56 def render_success(data: nil, message: nil, meta: {}, code: nil, pagination: nil, status: :ok) = code ? .merge(code: code, status: status) : payload = ResponseBuilder.new( success: true, data: data, message: , meta: , pagination: pagination, request: try(:request) ).build render json: payload, status: status end |
#render_switching_protocols(message: "Switching protocols", meta: {}) ⇒ Object
101 Switching Protocols
108 109 110 |
# File 'lib/respondo/controller_helpers.rb', line 108 def render_switching_protocols(message: "Switching protocols", meta: {}) render_success(data: nil, message: , meta: , code: 101, status: :switching_protocols) end |
#render_temporary_redirect(message: "Temporary redirect", meta: {}, pagination: nil) ⇒ Object
307 Temporary Redirect — repeat request with same method to new URL
208 209 210 |
# File 'lib/respondo/controller_helpers.rb', line 208 def render_temporary_redirect(message: "Temporary redirect", meta: {}, pagination: nil) render_success(data: nil, message: , meta: , pagination: pagination, code: 307, status: :temporary_redirect) end |
#render_too_early(message: "Too early", errors: nil, meta: {}) ⇒ Object
425 Too Early — server unwilling to risk processing replayed request
337 338 339 |
# File 'lib/respondo/controller_helpers.rb', line 337 def render_too_early(message: "Too early", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 425, status: :too_early) end |
#render_too_many_requests(message: "Too many requests. Please slow down.", errors: nil, meta: {}) ⇒ Object
429 Too Many Requests — rate limiting
352 353 354 |
# File 'lib/respondo/controller_helpers.rb', line 352 def render_too_many_requests(message: "Too many requests. Please slow down.", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 429, status: :too_many_requests) end |
#render_unauthorized(message: "Unauthorized", errors: nil, meta: {}) ⇒ Object
401 Unauthorized — not authenticated
227 228 229 |
# File 'lib/respondo/controller_helpers.rb', line 227 def (message: "Unauthorized", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 401, status: :unauthorized) end |
#render_unavailable_for_legal_reasons(message: "Unavailable for legal reasons", errors: nil, meta: {}) ⇒ Object
451 Unavailable for Legal Reasons — censored/DMCA etc.
362 363 364 |
# File 'lib/respondo/controller_helpers.rb', line 362 def render_unavailable_for_legal_reasons(message: "Unavailable for legal reasons", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 451, status: :unavailable_for_legal_reasons) end |
#render_unprocessable(message: "Validation failed", errors: nil, meta: {}) ⇒ Object
422 Unprocessable Entity — validation errors (most common for APIs)
322 323 324 |
# File 'lib/respondo/controller_helpers.rb', line 322 def render_unprocessable(message: "Validation failed", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 422, status: :unprocessable_content) end |
#render_unsupported_media_type(message: "Unsupported media type", errors: nil, meta: {}) ⇒ Object
415 Unsupported Media Type — wrong Content-Type header
297 298 299 |
# File 'lib/respondo/controller_helpers.rb', line 297 def render_unsupported_media_type(message: "Unsupported media type", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 415, status: :unsupported_media_type) end |
#render_upgrade_required(message: "Upgrade required", errors: nil, meta: {}) ⇒ Object
426 Upgrade Required — client must switch protocols
342 343 344 |
# File 'lib/respondo/controller_helpers.rb', line 342 def render_upgrade_required(message: "Upgrade required", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 426, status: :upgrade_required) end |
#render_uri_too_long(message: "URI too long", errors: nil, meta: {}) ⇒ Object
414 URI Too Long — request URI exceeds server limit
292 293 294 |
# File 'lib/respondo/controller_helpers.rb', line 292 def render_uri_too_long(message: "URI too long", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 414, status: :uri_too_long) end |
#render_variant_also_negotiates(message: "Variant also negotiates", errors: nil, meta: {}) ⇒ Object
506 Variant Also Negotiates — server configuration error
401 402 403 |
# File 'lib/respondo/controller_helpers.rb', line 401 def render_variant_also_negotiates(message: "Variant also negotiates", errors: nil, meta: {}) render_error(message: , errors: errors, meta: , code: 506, status: :variant_also_negotiates) end |