Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ic-kit-http #25

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open

feat: ic-kit-http #25

wants to merge 25 commits into from

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.

1 participant