Crates.io | crux_http |
lib.rs | crux_http |
version | 0.10.3 |
source | src |
created_at | 2022-12-15 16:51:12.130282 |
updated_at | 2024-10-23 09:29:14.989399 |
description | HTTP capability for use with crux_core |
homepage | |
repository | https://github.com/redbadger/crux/ |
max_upload_size | |
id | 738114 |
size | 131,961 |
This crate contains the Http
capability, which can be used to ask the Shell to
make an HTTP request.
For an example of how to use the capability, see the integration test.
The code for this was largely copied from
surf
with some modifications made to fit
into the crux paradigm.
Add crux_http
as a dependency in your app's Cargo.toml
.
This crate has a feature called typegen
which supports generation of code
(e.g. in TypeScript, Swift, Kotlin etc.) for the types that the Capability
passes over the bridge.
Crux apps usually contain a shared
crate for the behavioural "core" and a
shared_types
crate that is responsible for generating the types that are
shared between the core and the shell.
The shared
crate can re-export the capability with a typegen
feature that
depends on the typegen
feature of the Capability crate. This way, the shared
crate can ask the Capability to register its types for type generation.
e.g. in the shared
crate's Cargo.toml
:
[features]
typegen = ["crux_core/typegen", "crux_http/typegen"]
and in the shared_types
crate's Cargo.toml
:
[build-dependencies]
crux_core = { workspace = true, features = ["typegen"] }
shared = { path = "../shared", features = ["typegen"] }
Crux capabilities teach Crux how to interact with the shell when performing side effects. They do the following:
Request
struct to instruct the Shell how to perform the side
effect on behalf of the CoreResponse
struct to hold the data returned by the Shell after the
side effect has completedCommand
(describing the effect and its
continuation) that Crux can "execute"Note that because Swift has no namespacing, there is currently a requirement to ensure that
Request
andResponse
are unambiguously named (e.g.HttpRequest
andHttpResponse
).