Skip to main content

Crate alux_http_typescript

Crate alux_http_typescript 

Source
Expand description

§alux-http-typescript

alux-http-typescript interprets an alux-http program as the TypeScript client that calls it.

The same program an executing interpretation answers is read here from the other side: what a caller states, where each argument goes, and what comes back. Nothing about the surface is written a second time in another language, which is what makes a client and a service unable to disagree about it.

use alux_http::HttpProgramExt;
use alux_http_typescript::TsHttpClient;
use alux_shape::Spelling;

let client = TsHttpClient::new(Spelling::LowerCamel);
let module = client.compile_http(client.status_api::<App>());

println!("{}", module.render());

A generated module states each call as the program states it:

export const program = {
  readingAt: endpoint<[id: number], Reading>("GET", "/readings/{id}", ["path"]),
} as const

§One call per operation

Each call is named after the operation it calls. Declare the same operation on two endpoints and the module has one call, the last one declared. Give each endpoint its own operation to get two calls.

A server still answers both paths, and alux-http-text and alux-http-openapi still describe both.

The method, the path template, and where each argument goes are read from the declaration. A described path is already a template, so nothing is spelled a second way for a caller. endpoint comes from the runtime package, so a surface and what makes a surface’s requests are upgraded separately.

Interprets typed HTTP programs as the TypeScript client that calls them.

The same program an executing interpretation answers is read here from the other side: what a caller states, where each argument goes, and what comes back. Nothing about the surface is written a second time in another language.

Structs§

TsArgument
One argument, as a call takes it.
TsBodyInput
Takes a request body written as a document.
TsBytesOutput
Answers a caller with the bytes a raw-byte answer states.
TsCall
One call, before the method and path it is made under are composed around it.
TsCookieInput
Takes a cookie the caller sends.
TsEmptyOutput
Answers a caller with what an answer with no body states.
TsFileOutput
Answers a caller with the bytes a streamed file states.
TsFormInput
Takes a request body written as a form.
TsHeaderInput
Takes a header the caller sends.
TsHeaderOutput
Answers with what the kind beneath states, since a header reaches a caller beside it.
TsHtmlOutput
Answers a caller with what HTML states.
TsHttpClient
Interprets typed HTTP programs as a TypeScript client module.
TsHttpModule
A client module: the declarations its calls depend on, and the calls themselves.
TsJsonOutput
Answers with whatever the handler’s result states.
TsMultipartInput
Takes a request body written as parts.
TsPathInput
Takes a segment the path binds.
TsQueryInput
Takes a value in the query string.
TsRawBodyInput
Takes a request body sent as it stands.
TsRedirectOutput
Answers a caller with what a redirect states.
TsResultOutput
Answers with what the kind beneath states, since a failure rejects the call instead.
TsRouteImpl
Composes route selection as the method and path a call is made under.
TsSelector
Carries route-selection meaning, which a call reads as a method and a path template.
TsStatusOutput
Answers with what the kind beneath states, whatever status the endpoint declared.
TsStreamOutput
Answers a caller with the bytes a streamed answer states.
TsTextOutput
Answers a caller with what plain text states.
TsUnstatedInput
Takes nothing, because a caller states nothing here.

Enums§

TsSource
Where a call says one argument goes.

Constants§

RUNTIME_PACKAGE
The package that interprets a program: what turns one into calls, installed once.

Traits§

TsInputAlg
States how a call takes one argument.
TsInputsAlg
States the whole argument product a call takes, in declaration order.
TsOutputAlg
States what one output kind answers a caller with.