Response
Response module provides constructors and utilities for managing immutable interpretations of HTTP responses.
The Response Type
Section titled “The Response Type”A Response represents immutable and clonable HTTP Response data. It is a base element of the Response module.
import { import Response
Response } from 'fx-fetch';
type type Type = Response.Response
Type = import Response
Response.export Response
Represents immutable HTTP response.
Response;The Input Type
Section titled “The Input Type”A Response.Input represents all the possible inputs that can be used to create a Response.
Concrete types that make up the Input union:
import { import Response
Response } from 'fx-fetch';
type type Type = Response.Response | Response.Response.Parts | Response.Response.Options | Response
Type = import Response
Response.export Response
Represents immutable HTTP response.
Response.type Response.Input = Response.Response | Response.Response.Parts | Response.Response.Options | Response
Input;globalThis.Response— vanilla JS responseResponse.Response.Parts— Object with response partsResponse.Response— Existing Response can be used too
Constructors
Section titled “Constructors”unsafeMake
Section titled “unsafeMake”Creates a Response from any of Response.Input.
Throws an IllegalArgumentException if the provided input is invalid.
import { import Response
Response } from 'fx-fetch';// ┌─── Response.Response// ▼const const response: Response.Response
response = import Response
Response.function unsafeMake(input: Response.Response.Input): Response.Responseexport unsafeMake
Creates a immutable Response object.
unsafeMake({ body: string
body: 'Hello, world!', status: number
status: 200,});Similar to unsafeMake, but returns an Option instead of throwing an error if the input is invalid.
If the input is invalid, it returns None. If valid, it returns Some containing the Response.
import { import Option
Option } from 'effect';import { import Response
Response } from 'fx-fetch';// ┌─── Option.Option<Response.Response>// ▼const const response: Option.Option<Response.Response>
response = import Response
Response.function make(input: import("/home/runner/work/fx-fetch/fx-fetch/packages/fx-fetch/dist/Response/Response").Response.Input): Option.Option<import("/home/runner/work/fx-fetch/fx-fetch/packages/fx-fetch/dist/Response/Response").Response>export make
Creates a Response from the given input, returning None if the input is invalid.
make({ body: string
body: 'Hello, world!', status: number
status: 200,});from Response.Parts
Section titled “from Response.Parts”For creating a Response from an object Response.Parts use same functions make or unsafeMake.
The Parts type is super primitive. It’s basically an object with all the properties of a JS response, but with better DX.
Everything except the url is optional.
import { import Response
Response } from 'fx-fetch';
const const parts: Response.Response.Parts
parts: import Response
Response.export Response
Represents immutable HTTP response.
Response.type Response.Parts = { readonly body?: BodyInput; readonly headers?: HeadersInput; readonly redirected?: boolean; readonly status?: number; readonly statusText?: string; readonly type?: globalThis.ResponseType; readonly url?: Url.Input;}
Parts = { body?: any
body: 'Hello, world!', headers?: any
headers: { 'Content-Type': 'text/plain', 'X-Custom-Header': ['CustomValue', 'AnotherValue'], }, redirected?: boolean
redirected: false, status?: number
status: 200, statusText?: string
statusText: 'OK', type?: any
type: 'cors', url?: Url.Input
url: 'https://example.com/api',};
const const response: Response.Response
response = import Response
Response.function unsafeMake(input: Response.Response.Input): Response.Responseexport unsafeMake
Creates a immutable Response object.
unsafeMake(const parts: Response.Response.Parts
parts);Properties url and headers have flexible input types.
urlis of typeUrl.Input. Read more about it in Url module documentation.headerscan be almost anything what you can imagine as headers.- Record of strings
- Entries (array of tuples)
Mapof strings- Same as
HeadersInitin Fetch API - … many more…