Expand description
§Features
§d1
Allows the use of D1 bindings and query! macro.
§queue
Enables queue event type in [event] macro.
// Consume messages from a queue
#[event(queue)]
pub async fn main(message_batch: MessageBatch<MyType>, env: Env, _ctx: Context) -> Result<()> {
Ok(())
}§http
worker 0.0.21 introduced an http feature flag which starts to replace custom types with widely used types from the http crate.
This makes it much easier to use crates which use these standard types such as axum.
This currently does a few things:
- Introduce
Body, which implementshttp_body::Bodyand is a simple wrapper aroundweb_sys::ReadableStream. - The
reqargument when using the[event(fetch)]macro becomeshttp::Request<worker::Body>. - The expected return type for the fetch handler is
http::Response<B>whereBcan be anyhttp_body::Body<Data=Bytes>. - The argument for
Fetcher::fetch_requestishttp::Request<worker::Body>. - The return type of
Fetcher::fetch_requestishttp::Response<worker::Body>.
The end result is being able to use frameworks like axum directly (see example):
pub async fn root() -> &'static str {
"Hello Axum!"
}
fn router() -> Router {
Router::new().route("/", get(root))
}
#[event(fetch)]
async fn fetch(
req: HttpRequest,
_env: Env,
_ctx: Context,
) -> Result<http::Response<axum::body::Body>> {
Ok(router().call(req).await?)
}We also implement try_from between worker::Request and http::Request<worker::Body>, and between worker::Response and http::Response<worker::Body>. This allows you to convert your code incrementally if it is tightly coupled to the original types.
Re-exports§
Modules§
- Requires
d1feature. - Durable Objects provide low-latency coordination and consistent storage for the Workers platform. A given namespace can support essentially unlimited Durable Objects, with each Object having access to a transactional, key-value storage API.
Macros§
- When debugging your Worker via
wrangler dev,wrangler tail, or from the Workers Dashboard, anything passed to this macro will be printed to the terminal or written to the console. - When debugging your Worker via
wrangler dev,wrangler tail, or from the Workers Dashboard, anything passed to this macro will be printed to the terminal or written to the console. - When debugging your Worker via
wrangler dev,wrangler tail, or from the Workers Dashboard, anything passed to this macro will be printed to the terminal or written to the console. - When debugging your Worker via
wrangler dev,wrangler tail, or from the Workers Dashboard, anything passed to this macro will be printed to the terminal or written to the console. - Requires
d1feature. Prepare a D1 query from the provided D1Database, query string, and optional query parameters.
Structs§
- An interface that allows you to abort in-flight Fetch requests.
- An interface representing a signal that can be passed to cancellable operations, primarily a Fetch request.
- Requires
httpfeature. A convenience Body type which wrapsweb_sys::ReadableStreamand implementshttp_body::Body - An instance of the R2 bucket binding.
- Provides access to the Cache API. Because
matchis a reserved keyword in Rust, thematchmethod has been renamed toget. - In addition to the methods on the
Requeststruct, theCfstruct on an inbound Request contains information about the request provided by Cloudflare’s edge. - Wrapper/Utility struct for the
web_sys::CloseEvent - You can pass an Conditional object to GetOptionsBuilder. If the condition check fails, the body will not be returned. This will make get have lower latency.
- A context bound to a
fetchevent. - Cors struct, holding cors configuration
- Options for configuring the create_multipart_upload operation.
- The equivalent to a JavaScript
DateObject. - A Future for asynchronously waiting.
- A binding for dispatching events to Workers inside of a dispatch namespace by their name. This allows for your worker to directly invoke many workers by name instead of having multiple service worker bindings.
- Env contains any bindings you have associated with the Worker when you uploaded it.
- A
Streamthat yieldsWebsocketEvents emitted by the innerWebSocket. The stream is guaranteed to always yield aWebsocketEvent::Closeas the final non-none item. - A struct for invoking fetch events to other Workers.
- A File representation used with
FormData. - A FormData representation of the request body, providing access to form encoded fields and files.
- Options for configuring the get operation.
- A Headers representation used in Request and Response objects.
- Metadata that’s automatically rendered into R2 HTTP API endpoints.
- Options for configuring the list operation.
- Wrapper/Utility struct for the
web_sys::MessageEvent - Configuration options for Cloudflare’s minification features: https://www.cloudflare.com/website-optimization/
- The data contained within an Object.
- Options for configuring the put operation.
- A Request representation for handling incoming and creating outbound HTTP requests.
- Optional options struct that contains settings to apply to the
Request. - A Response representation for working with or returning a response to a
Request. - Container for a route’s parsed parameters, data, and environment bindings from the Runtime (such as KV Stores, Durable Objects, Variables, and Secrets).
- Represents the URL parameters parsed from the path, e.g. a route with “/user/:id” pattern would contain a single “id” key.
- A path-based HTTP router supporting exact-match or wildcard placeholders and shared data.
- Represents an outbound TCP connection from your Worker.
- The host and port that you wish to connect to.
- Used to configure outbound TCP connections.
- Only set when using Cloudflare Access or API Shield
- UploadedPart represents a part that has been uploaded. UploadedPart objects are returned from upload_part operations and must be passed to the complete operation.
- A parsed URL record.
- Wrapper struct for underlying worker-sys
WebSocket - Struct holding the values for a JavaScript
WebSocketPair
Enums§
- Successful outcomes when attempting to delete a
Responsefrom the cache - The
StringorRequestobject used as the lookup key.Strings are interpreted as the URL for a newRequestobject. - Initialize a
Dateby constructing this enum. - All possible Error variants that might be encountered while working with a Worker.
- Construct a Fetch call from a URL string or a Request object. Call its
sendmethod to execute the request. - Representing the options any FormData value can be, a field or a file.
- A
Methodrepresentation used on Request objects. - Configuration options for Cloudflare’s image optimization feature: https://blog.cloudflare.com/introducing-polish-automatic-image-optimizati/
- Secure transport options for outbound TCP connections.
- Events that can be yielded by a
EventStream.
Traits§
Functions§
- Requires
httpfeature. Convert generichttp::Response<B>toweb_sys::ResopnsewhereBcan be anyhttp_body::Body
Type Aliases§
- Requires
httpfeature. Type alias forhttp::Request<worker::Body>. - Requires
httpfeature. Type alias forhttp::Response<worker::Body>. - A string value representing a binding to a secret in a Worker.
- A string value representing a binding to an environment variable in a Worker.