Skip to content

Conversation

@ozwaldorf
Copy link
Collaborator

@ozwaldorf ozwaldorf commented Sep 17, 2022

Adds HTTP routing to kit canisters!

Currently, the functionality is provided as a flag on ic-kit, and will enable the required features in the kit macros.

Example

An example HTTP pastebin is provided in the examples

use ic_kit::prelude::*;

#[get(route = "/")]
fn index_handler(_: HttpRequest, _: Params) -> HttpResponse {
    HttpResponse {
        status_code: 200,
        headers: vec![],
        body: b"this is an example".into(),
        streaming_strategy: None,
        upgrade: false,
    }
}

How it works?

Internally, for the routing, we use matchit, a blazing fast URL router. Routing happens within the nanosecond scale :) This is the same library used for cloudflare/worker-rs

Tasks

  • initial implementation (get only)
  • Support all HTTP methods (get, put, post, options, head, patch, delete, connect)
  • simple pastebin example (basic usage + canister side rendering)
  • Helper for getting a specific header field from an HttpRequest
  • Helpers for building an HttpResponse
  • DI support (integrate into existing entrypoint instead of custom)
  • graceful error macros + routing (handlers should return Results, catch error and route accordingly)

@ozwaldorf ozwaldorf changed the title feat: initial implementation for ic-kit-http, supports only GET feat: initial implementation for ic-kit-http Sep 17, 2022
@ozwaldorf ozwaldorf changed the title feat: initial implementation for ic-kit-http feat: ic-kit-http Sep 17, 2022
@ozwaldorf ozwaldorf changed the title feat: ic-kit-http feat: ic-kit-http (WIP) Sep 17, 2022
@ozwaldorf ozwaldorf changed the title feat: ic-kit-http (WIP) feat: ic-kit-http Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants