An adapter to easily allow an Axum server to be run within a Cloudflare worker.

Overview

axum-cloudflare-adapter

Crates.io

An adapter to easily allow an Axum server to be run within a Cloudflare worker.

Usage

use worker::*;

use axum::{
    response::{Html},
    routing::get,
    Router as AxumRouter,
};
use axum_cloudflare_adapter::{to_axum_request, to_worker_response};
use tower_service::Service;

async fn index() -> Html<&'static str> {
		Html("<p>Hello from Axum!</p>")
}

#[event(fetch)]
pub async fn main(req: Request, _env: Env, _ctx: worker::Context) -> Result<Response> {
    let mut _router: AxumRouter = AxumRouter::new()
            .route("/", get(index));
    
    let axum_request = to_axum_request(req).await.unwrap();
    let axum_response = _router.call(axum_request).await.unwrap();
    let response = to_worker_response(axum_response).await.unwrap();
    
    Ok(response)
}

Running tests

wasm-pack test --firefox --headless

Building

cargo build --target wasm32-unknown-unknown

Example

The /example directory contains a Cloudflare worker running an Axum sever

You might also like...
🔎 Prometheus metrics middleware for Axum

Axum-Prometheus A Prometheus middleware to collect HTTP metrics for Axum applications. axum-prometheus relies on metrics_exporter_prometheus as a back

Provides json/csv/protobuf streaming support for axum

axum streams for Rust Library provides HTTP response streaming support for axum web framework: JSON array stream format JSON lines stream format CSV s

Simple example of axum, sqlx with sqlite and utoipa (swagger) - without auth

axum_crud_api Simple example to learn creating CRUD rest apis in Rust with axum, sqlx with sqlite and utoipa (swagger) - without auth Also shows how t

Heavy Metal Leptos Stack with Tailwind, Axum, Sqlite, and Cargo Leptos

Heavy Metal Stack Leptos stack with Axum, TailwindCSS, and Sqlite This example creates a basic todo app with an Axum backend that uses Leptos' server

A crate built on top of `axum-sessions`, implementing the CSRF Synchronizer Token Pattern

Axum Synchronizer Token Pattern CSRF prevention This crate provides a Cross-Site Request Forgery protection layer and middleware for use with the axum

Rate Limiting middleware for Tower/Axum/Tonic/Hyper utilizing the governor crate

A Tower service and layer that provides a rate-limiting backend by governor. Based heavily on the work done for actix-governor. Works with Axum, Hyper

Starter template for use with the Leptos web framework and Axum.

Leptos Axum Starter Template This is a template for use with the Leptos web framework and the cargo-leptos tool using Axum. Creating your template rep

Type safe multipart/form-data handling for axum.

axum_typed_multipart Designed to seamlessly integrate with Axum, this crate simplifies the process of handling multipart/form-data requests in your we

Axum + Connect-Web = ♥️

Axum Connect-Web ⚠️ This project isn't even Alpha state yet. Don't use it. Brings the protobuf-based Connect-Web RPC framework to Rust via idiomatic A

Comments
  • Update worker requirement from 0.0.12  to 0.0.13

    Update worker requirement from 0.0.12 to 0.0.13

    Updates the requirements on worker to permit the latest version.

    Release notes

    Sourced from worker's releases.

    Release v0.0.13

    Full Changelog: https://github.com/cloudflare/workers-rs/compare/v0.0.12...v0.0.13

    Commits
    • fd21831 chore: increment crate versions
    • b4b9cd1 fix: buffer R2 reads when not explicitly streaming
    • 4be1f69 Pin 'wasm-bindgen' version to 0.2.84
    • 870f65d Correct bindgen glue import in worker-build
    • ff678bc worker-sandbox: Add a test for the multipart upload.
    • 1205fb4 Change the type of complete()'s argumento to IntoIterator.
    • fee53f7 Add documentation.
    • 0db01c3 Add support for multipart uploads.
    • 0d05c45 Merge pull request #272 from cloudflare/zeb/fix-clippy
    • f70a805 chore: fix new clippy lints
    • Additional commits viewable in compare view

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 1
Releases(0.2.0)
  • 0.2.0(Mar 4, 2023)

    • BREAKING: public functions will return Result<T, Error> to allow consumers to handle errors rather than panic.
    • PATCH: Update worker to 0.0.13
    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Feb 27, 2023)

    Initial Release

    • Feature: allows a Cloudflare Worker Request to be converted to an Axum Request
    • Feature: allows an Axum Response to be converted to a Cloudflare Worker Response
    Source code(tar.gz)
    Source code(zip)
Owner
Logan Keenan
Logan Keenan
Rust server with Axum, GraphQL and SurrealDb

??️ Article on my web Axum server, Async-GraphQl, SurrealDB template Run without any prior setup, DB is in memory: cargo run To use routes other than

null 15 Jun 26, 2023
An async no_std HTTP server suitable for bare-metal environments, heavily inspired by axum

picoserve An async no_std HTTP server suitable for bare-metal environments, heavily inspired by axum. It was designed with embassy on the Raspberry Pi

Samuel Hicks 81 Oct 7, 2023
Rust/Axum server implementation with PCR(Prisma Client Rust)

Realworld Rust Axum Prisma This project utilizes Rust with the Axum v0.7 framework along with the Prisma Client Rust to build a realworld application.

Neo 3 Dec 9, 2023
Experiments with Rust CRDTs using Tokio web application framework Axum.

crdt-genome Synopsis Experiments with Rust CRDTs using Tokio web application framework Axum. Background Exploring some ideas of Martin Kleppmann, part

dougfort 3 Mar 18, 2022
Axum web framework tutorial for beginners.

Axum Tutorial For Beginners Hello web developers! This tutorial will cover how to write simple web applications in rust with axum framework. If you ar

Eray Karatay 46 Jan 5, 2023
Yew + Axum + blog = Yab

Yew + Axum + blog = Yab

STUDIO RSBM 13 Dec 5, 2022
Demo of Rust and axum web framework

Demo of Rust and axum web framework Demonstration of: Rust: programming language that focuses on reliability and stability. axum: web framework that f

Joel Parker Henderson 115 Dec 29, 2022
Rust Axum+SQLx Sample

rust-axum-sqlx-sample Install git clone https://github.com/web3ten0/rust-axum-sqlx-1.git cd rust-axum-sqlx-1/local docker-compose up -d sh scripts/exe

web3ten0 5 Jul 9, 2022
🪪 Session-based user authentication for Axum.

axum-login ?? Session-based user authentication for Axum. ?? Overview axum-login is a Tower middleware providing session-based user authentication for

Max Countryman 99 Jan 5, 2023
Layers, extractors and template engine wrappers for axum based Web MVC applications

axum-template Layers, extractors and template engine wrappers for axum based Web MVC applications Getting started Cargo.toml [dependencies] axum-templ

Altair Bueno 11 Dec 15, 2022