Trait Resource

Source
pub trait Resource: Debug {
Show 34 methods // Provided methods fn finalise_response(&self, _context: &mut WebmachineContext) { ... } fn render_response<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 mut WebmachineContext, ) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>>> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn available(&self, _context: &mut WebmachineContext) -> bool { ... } fn known_methods(&self) -> Vec<&str> { ... } fn uri_too_long(&self, _context: &mut WebmachineContext) -> bool { ... } fn allowed_methods(&self) -> Vec<&str> { ... } fn malformed_request(&self, _context: &mut WebmachineContext) -> bool { ... } fn not_authorized(&self, _context: &mut WebmachineContext) -> Option<String> { ... } fn forbidden(&self, _context: &mut WebmachineContext) -> bool { ... } fn unsupported_content_headers( &self, _context: &mut WebmachineContext, ) -> bool { ... } fn acceptable_content_types( &self, _context: &mut WebmachineContext, ) -> Vec<&str> { ... } fn valid_entity_length(&self, _context: &mut WebmachineContext) -> bool { ... } fn finish_request(&self, context: &mut WebmachineContext) { ... } fn options( &self, _context: &mut WebmachineContext, ) -> Option<HashMap<String, Vec<String>>> { ... } fn produces(&self) -> Vec<&str> { ... } fn languages_provided(&self) -> Vec<&str> { ... } fn charsets_provided(&self) -> Vec<&str> { ... } fn encodings_provided(&self) -> Vec<&str> { ... } fn variances(&self) -> Vec<&str> { ... } fn resource_exists<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 mut WebmachineContext, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn previously_existed(&self, _context: &mut WebmachineContext) -> bool { ... } fn moved_permanently( &self, _context: &mut WebmachineContext, ) -> Option<String> { ... } fn moved_temporarily( &self, _context: &mut WebmachineContext, ) -> Option<String> { ... } fn is_conflict(&self, _context: &mut WebmachineContext) -> bool { ... } fn allow_missing_post(&self, _context: &mut WebmachineContext) -> bool { ... } fn generate_etag(&self, _context: &mut WebmachineContext) -> Option<String> { ... } fn last_modified( &self, _context: &mut WebmachineContext, ) -> Option<DateTime<FixedOffset>> { ... } fn delete_resource<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 mut WebmachineContext, ) -> Pin<Box<dyn Future<Output = Result<bool, u16>> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn post_is_create(&self, _context: &mut WebmachineContext) -> bool { ... } fn process_post<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 mut WebmachineContext, ) -> Pin<Box<dyn Future<Output = Result<bool, u16>> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn create_path<'life0, 'life1, 'async_trait>( &'life0 self, context: &'life1 mut WebmachineContext, ) -> Pin<Box<dyn Future<Output = Result<String, u16>> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn process_put<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 mut WebmachineContext, ) -> Pin<Box<dyn Future<Output = Result<bool, u16>> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn multiple_choices(&self, _context: &mut WebmachineContext) -> bool { ... } fn expires( &self, _context: &mut WebmachineContext, ) -> Option<DateTime<FixedOffset>> { ... }
}
Expand description

All webmachine resources implement this trait

Provided Methods§

Source

fn finalise_response(&self, _context: &mut WebmachineContext)

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.

Source

fn render_response<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 mut WebmachineContext, ) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

This is invoked to render the response for the resource

Source

fn available(&self, _context: &mut WebmachineContext) -> 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.

Source

fn known_methods(&self) -> Vec<&str>

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

Source

fn uri_too_long(&self, _context: &mut WebmachineContext) -> 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.

Source

fn allowed_methods(&self) -> Vec<&str>

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

Source

fn malformed_request(&self, _context: &mut WebmachineContext) -> bool

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

Source

fn not_authorized(&self, _context: &mut WebmachineContext) -> 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.

Source

fn forbidden(&self, _context: &mut WebmachineContext) -> bool

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

Source

fn unsupported_content_headers(&self, _context: &mut WebmachineContext) -> 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.

Source

fn acceptable_content_types( &self, _context: &mut WebmachineContext, ) -> Vec<&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. Wild cards can be used, like */*, type/* or */sub-type.

Source

fn valid_entity_length(&self, _context: &mut WebmachineContext) -> 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.

Source

fn finish_request(&self, context: &mut WebmachineContext)

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

Source

fn options( &self, _context: &mut WebmachineContext, ) -> 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.

Source

fn produces(&self) -> Vec<&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.

Source

fn languages_provided(&self) -> Vec<&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.

Source

fn charsets_provided(&self) -> Vec<&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.

Source

fn encodings_provided(&self) -> Vec<&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.

Source

fn variances(&self) -> Vec<&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.

Source

fn resource_exists<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 mut WebmachineContext, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

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.

Source

fn previously_existed(&self, _context: &mut WebmachineContext) -> bool

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

Source

fn moved_permanently(&self, _context: &mut WebmachineContext) -> 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

Source

fn moved_temporarily(&self, _context: &mut WebmachineContext) -> 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

Source

fn is_conflict(&self, _context: &mut WebmachineContext) -> bool

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

Source

fn allow_missing_post(&self, _context: &mut WebmachineContext) -> bool

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

Source

fn generate_etag(&self, _context: &mut WebmachineContext) -> 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.

Source

fn last_modified( &self, _context: &mut WebmachineContext, ) -> 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

Source

fn delete_resource<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 mut WebmachineContext, ) -> Pin<Box<dyn Future<Output = Result<bool, u16>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

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).

Source

fn post_is_create(&self, _context: &mut WebmachineContext) -> 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.

Source

fn process_post<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 mut WebmachineContext, ) -> Pin<Box<dyn Future<Output = Result<bool, u16>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

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.

Source

fn create_path<'life0, 'life1, 'async_trait>( &'life0 self, context: &'life1 mut WebmachineContext, ) -> Pin<Box<dyn Future<Output = Result<String, u16>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

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.

Source

fn process_put<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 mut WebmachineContext, ) -> Pin<Box<dyn Future<Output = Result<bool, u16>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

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)

Source

fn multiple_choices(&self, _context: &mut WebmachineContext) -> 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.

Source

fn expires( &self, _context: &mut WebmachineContext, ) -> Option<DateTime<FixedOffset>>

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

Implementors§