Calls
Send a body
Send JSON, form data, text or bytes, encoded with a schema or as is.
Send a request body with post, put, patch or del. Effetch sends the
body according to its type, and an input schema types and encodes it.
Send JSON or a form
The following calls send a body encoded with an input schema, a plain JSON
body, and a FormData you build yourself:
import * as from "effect/Schema";
import type { } from "@monarcode/effetch";
declare const : .;
const = .({
: .,
: .,
: .,
: .,
});
const = .({ : ., : . });
export const = .("/todos", {
: ,
: { : "Write docs", : new () },
: ,
});
export const = .("/todos/:id", {
: { : 1 },
: { : true },
: ,
});
export const = (: ) => {
const = new ();
.("file", );
return .("/uploads", { : });
};How a body is sent
A body is sent according to its type:
- an
HttpBody, a string, anArrayBufferor typed array, aBloborFile,FormDataandURLSearchParamsare sent as they are; - anything else is sent as JSON.
Encode the body with a schema
Add an input schema, and body is typed by it and encoded with it before
it's sent as JSON. In create, due is a Date in your code and an ISO
string on the wire.
To send a typed body as a form instead, such as a file upload, see Upload files.
What's next
- Upload files: send a typed body as
multipart/form-data. - Read the response: decode what the server sends back.
- Call options: look up every option a call takes.