logo
pub struct Resource<'a> {
Show 34 fields pub finalise_response: Option<Callback<'a, ()>>, pub render_response: Callback<'a, Option<String>>, pub available: Callback<'a, bool>, pub known_methods: Vec<&'a str>, pub uri_too_long: Callback<'a, bool>, pub allowed_methods: Vec<&'a str>, pub malformed_request: Callback<'a, bool>, pub not_authorized: Callback<'a, Option<String>>, pub forbidden: Callback<'a, bool>, pub unsupported_content_headers: Callback<'a, bool>, pub acceptable_content_types: Vec<&'a str>, pub valid_entity_length: Callback<'a, bool>, pub finish_request: Callback<'a, ()>, pub options: Callback<'a, Option<HashMap<String, Vec<String>>>>, pub produces: Vec<&'a str>, pub languages_provided: Vec<&'a str>, pub charsets_provided: Vec<&'a str>, pub encodings_provided: Vec<&'a str>, pub variances: Vec<&'a str>, pub resource_exists: Callback<'a, bool>, pub previously_existed: Callback<'a, bool>, pub moved_permanently: Callback<'a, Option<String>>, pub moved_temporarily: Callback<'a, Option<String>>, pub is_conflict: Callback<'a, bool>, pub allow_missing_post: Callback<'a, bool>, pub generate_etag: Callback<'a, Option<String>>, pub last_modified: Callback<'a, Option<DateTime<FixedOffset>>>, pub delete_resource: Callback<'a, Result<bool, u16>>, pub post_is_create: Callback<'a, bool>, pub process_post: Callback<'a, Result<bool, u16>>, pub create_path: Callback<'a, Result<String, u16>>, pub process_put: Callback<'a, Result<bool, u16>>, pub multiple_choices: Callback<'a, bool>, pub expires: Callback<'a, Option<DateTime<FixedOffset>>>,
}
Expand description

Struct to represent a resource in webmachine

Fields

finalise_response: Option<Callback<'a, ()>>

This is called just before the final response is constructed and sent. It allows the resource an opportunity to modify the response after the webmachine has executed.

render_response: Callback<'a, Option<String>>

This is invoked to render the response for the resource

available: Callback<'a, bool>

Is the resource available? Returning false will result in a ‘503 Service Not Available’ response. Defaults to true. If the resource is only temporarily not available, add a ‘Retry-After’ response header.

known_methods: Vec<&'a str>

HTTP methods that are known to the resource. Default includes all standard HTTP methods. One could override this to allow additional methods

uri_too_long: Callback<'a, bool>

If the URI is too long to be processed, this should return true, which will result in a ‘414 Request URI Too Long’ response. Defaults to false.

allowed_methods: Vec<&'a str>

HTTP methods that are allowed on this resource. Defaults to GET’,’HEAD and ‘OPTIONS’.

malformed_request: Callback<'a, bool>

If the request is malformed, this should return true, which will result in a ‘400 Malformed Request’ response. Defaults to false.

not_authorized: Callback<'a, Option<String>>

Is the client or request not authorized? Returning a Some will result in a ‘401 Unauthorized’ response. Defaults to None. If a Some(String) is returned, the string will be used as the value in the WWW-Authenticate header.

forbidden: Callback<'a, bool>

Is the request or client forbidden? Returning true will result in a ‘403 Forbidden’ response. Defaults to false.

unsupported_content_headers: Callback<'a, bool>

If the request includes any invalid Content-* headers, this should return true, which will result in a ‘501 Not Implemented’ response. Defaults to false.

acceptable_content_types: Vec<&'a str>

The list of acceptable content types. Defaults to ‘application/json’. If the content type of the request is not in this list, a ‘415 Unsupported Media Type’ response is returned.

valid_entity_length: Callback<'a, bool>

If the entity length on PUT or POST is invalid, this should return false, which will result in a ‘413 Request Entity Too Large’ response. Defaults to true.

finish_request: Callback<'a, ()>

This is called just before the final response is constructed and sent. This allows the response to be modified. The default implementation adds CORS headers to the response

options: Callback<'a, Option<HashMap<String, Vec<String>>>>

If the OPTIONS method is supported and is used, this returns a HashMap of headers that should appear in the response. Defaults to CORS headers.

produces: Vec<&'a str>

The list of content types that this resource produces. Defaults to ‘application/json’. If more than one is provided, and the client does not supply an Accept header, the first one will be selected.

languages_provided: Vec<&'a str>

The list of content languages that this resource provides. Defaults to an empty list, which represents all languages. If more than one is provided, and the client does not supply an Accept-Language header, the first one will be selected.

charsets_provided: Vec<&'a str>

The list of charsets that this resource provides. Defaults to an empty list, which represents all charsets with ISO-8859-1 as the default. If more than one is provided, and the client does not supply an Accept-Charset header, the first one will be selected.

encodings_provided: Vec<&'a str>

The list of encodings your resource wants to provide. The encoding will be applied to the response body automatically by Webmachine. Default includes only the ‘identity’ encoding.

variances: Vec<&'a str>

The list of header names that should be included in the response’s Vary header. The standard content negotiation headers (Accept, Accept-Encoding, Accept-Charset, Accept-Language) do not need to be specified here as Webmachine will add the correct elements of those automatically depending on resource behavior. Default is an empty list.

resource_exists: Callback<'a, bool>

Does the resource exist? Returning a false value will result in a ‘404 Not Found’ response unless it is a PUT or POST. Defaults to true.

previously_existed: Callback<'a, bool>

If this resource is known to have existed previously, this should return true. Default is false.

moved_permanently: Callback<'a, Option<String>>

If this resource has moved to a new location permanently, this should return the new location as a String. Default is to return None

moved_temporarily: Callback<'a, Option<String>>

If this resource has moved to a new location temporarily, this should return the new location as a String. Default is to return None

is_conflict: Callback<'a, bool>

If this returns true, the client will receive a ‘409 Conflict’ response. This is only called for PUT requests. Default is false.

allow_missing_post: Callback<'a, bool>

Return true if the resource accepts POST requests to nonexistent resources. Defaults to false.

generate_etag: Callback<'a, Option<String>>

If this returns a value, it will be used as the value of the ETag header and for comparison in conditional requests. Default is None.

last_modified: Callback<'a, Option<DateTime<FixedOffset>>>

Returns the last modified date and time of the resource which will be added as the Last-Modified header in the response and used in negotiating conditional requests. Default is None

delete_resource: Callback<'a, Result<bool, u16>>

Called when a DELETE request should be enacted. Return Ok(true) if the deletion succeeded, and Ok(false) if the deletion was accepted but cannot yet be guaranteed to have finished. If the delete fails for any reason, return an Err with the status code you wish returned (a 500 status makes sense). Defaults to Ok(true).

post_is_create: Callback<'a, bool>

If POST requests should be treated as a request to put content into a (potentially new) resource as opposed to a generic submission for processing, then this should return true. If it does return true, then create_path will be called and the rest of the request will be treated much like a PUT to the path returned by that call. Default is false.

process_post: Callback<'a, Result<bool, u16>>

If post_is_create returns false, then this will be called to process any POST request. If it succeeds, return Ok(true), Ok(false) otherwise. If it fails for any reason, return an Err with the status code you wish returned (e.g., a 500 status makes sense). Default is false. If you want the result of processing the POST to be a redirect, set context.redirect to true.

create_path: Callback<'a, Result<String, u16>>

This will be called on a POST request if post_is_create returns true. It should create the new resource and return the path as a valid URI part following the dispatcher prefix. That path will replace the previous one in the return value of WebmachineRequest.request_path for all subsequent resource function calls in the course of this request and will be set as the value of the Location header of the response. If it fails for any reason, return an Err with the status code you wish returned (e.g., a 500 status makes sense). Default will return an Ok(WebmachineRequest.request_path). If you want the result of processing the POST to be a redirect, set context.redirect to true.

process_put: Callback<'a, Result<bool, u16>>

This will be called to process any PUT request. If it succeeds, return Ok(true), Ok(false) otherwise. If it fails for any reason, return an Err with the status code you wish returned (e.g., a 500 status makes sense). Default is Ok(true)

multiple_choices: Callback<'a, bool>

If this returns true, then it is assumed that multiple representations of the response are possible and a single one cannot be automatically chosen, so a 300 Multiple Choices will be sent instead of a 200. Default is false.

expires: Callback<'a, Option<DateTime<FixedOffset>>>

If the resource expires, this should return the date/time it expires. Default is None.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more