Module

Yoga.Fetch.Om

Package
purescript-yoga-fetch-om
Repository
rowtype-yoga/purescript-yoga-fetch-om

#client Source

client :: forall @routes routesRow ctx extraErr clientsRow. RecordRow routes routesRow => DeriveClient ctx extraErr routesRow clientsRow => String -> Record clientsRow

Derive API client functions from route definitions using VTA. Generated fields use ordinary function application. Path parameters are plain records; optional query parameters are explicit Maybe fields.

type UserAPI = { getUser :: Route ... }
api = client @UserAPI "https://api.example.com"
user <- api.getUser { id: 42 }
users <- api.listUsers { limit: Just 10, offset: Nothing }
health <- api.health

#clientWith Source

clientWith :: forall @routes @providedHeaders @providedQuery routesRow ctx extraErr clientsRow. RecordRow routes routesRow => DeriveClientWith providedHeaders providedQuery ctx extraErr routesRow clientsRow => ClientWithConfig ctx extraErr providedHeaders providedQuery -> Record clientsRow

#ClientInputs Source

type ClientInputs :: Row Type -> Row Type -> Typetype ClientInputs providedHeaders providedQuery = { headers :: Record providedHeaders, query :: Record providedQuery }

#ClientWithConfig Source

type ClientWithConfig :: Row Type -> Row Type -> Row Type -> Row Type -> Typetype ClientWithConfig ctx err providedHeaders providedQuery = { baseUrl :: Om (Record ctx) err String, provide :: Om (Record ctx) err (ClientInputs providedHeaders providedQuery) }

#deriveClient Source

deriveClient :: forall @routesRow ctx extraErr clientsRow. DeriveClient ctx extraErr routesRow clientsRow => String -> Record clientsRow

Deprecated: Use client with VTA instead

api = deriveClient @UserAPI "https://api.example.com"

#DeriveClient Source

class DeriveClient :: Row Type -> Row Type -> Row Type -> Row Type -> Constraintclass DeriveClient ctx extraErr routesRow clientsRow | routesRow ctx extraErr -> clientsRow where

Members

Instances

#DeriveClientRL Source

class DeriveClientRL :: Row Type -> Row Type -> RowList Type -> Row Type -> Row Type -> Constraintclass DeriveClientRL ctx extraErr rl acc out | ctx extraErr rl acc -> out where

Members

Instances

#DeriveClientFn Source

class DeriveClientFn :: forall k1. Type -> k1 -> Type -> Row Type -> Row Type -> Row Type -> Row Type -> Type -> Type -> Constraintclass DeriveClientFn method segments request response ctx extraErr routeErrors result fn | method segments request response -> routeErrors result, method segments request response ctx extraErr -> fn where

Members

Instances

#DeriveClientFnWith Source

class DeriveClientFnWith :: forall k1. Type -> k1 -> Type -> Row Type -> Row Type -> Row Type -> Row Type -> Row Type -> Row Type -> Type -> Type -> Constraintclass DeriveClientFnWith method segments request response providedHeaders providedQuery ctx extraErr routeErrors result fn | method segments request response -> routeErrors result, method segments request response providedHeaders providedQuery ctx extraErr -> fn where

Members

Instances

#DeriveClientWith Source

class DeriveClientWith :: Row Type -> Row Type -> Row Type -> Row Type -> Row Type -> Row Type -> Constraintclass DeriveClientWith providedHeaders providedQuery ctx extraErr routesRow clientsRow | providedHeaders providedQuery routesRow ctx extraErr -> clientsRow where

Members

Instances

#DeriveClientWithRL Source

class DeriveClientWithRL :: Row Type -> Row Type -> Row Type -> Row Type -> RowList Type -> Row Type -> Row Type -> Constraintclass DeriveClientWithRL providedHeaders providedQuery ctx extraErr rl acc out | providedHeaders providedQuery ctx extraErr rl acc -> out where

Members

Instances

#RecordRow Source

class RecordRow :: Type -> Row Type -> Constraintclass RecordRow t r | t -> r

Extract row type from Record type

Instances

#ToHeaders Source

class ToHeaders :: RowList Type -> Row Type -> Constraintclass ToHeaders headersRL headers  where

Members

Instances

Re-exports from Yoga.Fetch.Om.Simple

#FetchResponse Source

type FetchResponse a = { body :: a, headers :: Headers }

#FetchError Source

type FetchError = { body :: String, status :: Int }

#DecodeResponse Source

class DecodeResponse :: forall k. k -> Type -> Constraintclass DecodeResponse a result | a -> result where

Members

Instances

#put_ Source

put_ :: forall headers body ctx err. Homogeneous headers String => WriteForeign body => String -> Record headers -> body -> Om ctx (fetchError :: FetchError | err) Unit

#putWithHeaders Source

putWithHeaders :: forall @a result headers body ctx err. DecodeResponse a result => Homogeneous headers String => WriteForeign body => String -> Record headers -> body -> Om ctx (fetchError :: FetchError | err) (FetchResponse result)

#put Source

put :: forall @a result headers body ctx err. DecodeResponse a result => Homogeneous headers String => WriteForeign body => String -> Record headers -> body -> Om ctx (fetchError :: FetchError | err) result

#post_ Source

post_ :: forall headers body ctx err. Homogeneous headers String => WriteForeign body => String -> Record headers -> body -> Om ctx (fetchError :: FetchError | err) Unit

#postWithHeaders Source

postWithHeaders :: forall @a result headers body ctx err. DecodeResponse a result => Homogeneous headers String => WriteForeign body => String -> Record headers -> body -> Om ctx (fetchError :: FetchError | err) (FetchResponse result)

#post Source

post :: forall @a result headers body ctx err. DecodeResponse a result => Homogeneous headers String => WriteForeign body => String -> Record headers -> body -> Om ctx (fetchError :: FetchError | err) result

#patch_ Source

patch_ :: forall headers body ctx err. Homogeneous headers String => WriteForeign body => String -> Record headers -> body -> Om ctx (fetchError :: FetchError | err) Unit

#patchWithHeaders Source

patchWithHeaders :: forall @a result headers body ctx err. DecodeResponse a result => Homogeneous headers String => WriteForeign body => String -> Record headers -> body -> Om ctx (fetchError :: FetchError | err) (FetchResponse result)

#patch Source

patch :: forall @a result headers body ctx err. DecodeResponse a result => Homogeneous headers String => WriteForeign body => String -> Record headers -> body -> Om ctx (fetchError :: FetchError | err) result

#getWithHeaders Source

getWithHeaders :: forall @a result headers ctx err. DecodeResponse a result => Homogeneous headers String => String -> Record headers -> Om ctx (fetchError :: FetchError | err) (FetchResponse result)

#get Source

get :: forall @a result headers ctx err. DecodeResponse a result => Homogeneous headers String => String -> Record headers -> Om ctx (fetchError :: FetchError | err) result

#delete_ Source

delete_ :: forall headers ctx err. Homogeneous headers String => String -> Record headers -> Om ctx (fetchError :: FetchError | err) Unit

#deleteWithHeaders Source

deleteWithHeaders :: forall @a result headers ctx err. DecodeResponse a result => Homogeneous headers String => String -> Record headers -> Om ctx (fetchError :: FetchError | err) (FetchResponse result)

#delete Source

delete :: forall @a result headers ctx err. DecodeResponse a result => Homogeneous headers String => String -> Record headers -> Om ctx (fetchError :: FetchError | err) result

Re-exports from Yoga.Fetch.Om.StreamDecode

#StreamDecode Source

Re-exports from Yoga.HTTP.API.Path

#Root Source

data Root

Root path representing "/"

Example: Path Root -- /

Instances

#Required Source

data Required a

Marker for required query parameters (default is optional → Maybe)

Example: Path ("users") :? (limit :: Int, offset :: Required Int) -- limit parses as Maybe Int, offset parses as Int (fails if missing)

#QueryParams Source

data QueryParams :: forall k. k -> Type -> Typedata QueryParams path params

Attach query parameters to a path

Example: Path ("users" / "id" : Int) :? { limit :: Int, offset :: Required Int }

Instances

#PathCons Source

data PathCons :: forall k1 k2. k1 -> k2 -> Typedata PathCons left right

Instances

#Path Source

data Path :: forall k. k -> Typedata Path segments

Type-level path representation

Examples: Path Root -- / Path (Lit "users") -- /users Path (Lit "users" / Capture "id" Int) -- /users/:id Path (Lit "users" / Capture "id" Int / Lit "posts") -- /users/:id/posts

Instances

#Param Source

data Param :: Symbol -> Type -> Typedata Param (name :: Symbol) (ty :: Type)

Sugar for Capture — use with bare Symbols in the path DSL

Example: Path ("users" / "id" : Int / "posts") -- equivalent to: Path (Lit "users" / Capture "id" Int / Lit "posts")

Instances

#Lit Source

data Lit :: Symbol -> Typedata Lit (segment :: Symbol)

Literal path segment (wrapper for Symbol to work around PureScript 0.15 limitations)

In PureScript 0.15, we can't use bare Symbols like Path "users" due to kind inference. Instead, use: Path (Lit "users")

Example: Path (Lit "users") -- /users Path (Lit "users" / Capture "id" Int) -- /users/:id

Instances

#Capture Source

data Capture :: Symbol -> Type -> Typedata Capture (name :: Symbol) (ty :: Type)

Capture a path parameter with a name and type

Example: Capture "id" Int -- captures :id as an Int Capture "name" String -- captures :name as a String

Instances

#PathPattern Source

class PathPattern :: forall k. k -> Constraintclass PathPattern path 

Generate a Fastify-compatible URL pattern from a path type

Examples: pathPattern (Proxy :: _ (Path Root)) = "/" pathPattern (Proxy :: _ (Path (Lit "users"))) = "/users" pathPattern (Proxy :: _ (Path (Lit "users" / Capture "id" Int))) = "/users/:id" pathPattern (Proxy :: _ ("users" / "id" : Int)) = "/users/:id"

Instances

#type (:?) Source

Operator alias for Yoga.HTTP.API.Path.QueryParams (left-associative / precedence 1)

#type (:) Source

Operator alias for Yoga.HTTP.API.Path.Param (right-associative / precedence 8)

#type (/) Source

Operator alias for Yoga.HTTP.API.Path.PathCons (right-associative / precedence 6)

Infix operator for building paths

Example: Lit "users" / Capture "id" Int / Lit "posts"

Re-exports from Yoga.HTTP.API.Route

#Streaming Source

data Streaming t0

A standards-based Web ReadableStream used as an HTTP response body. pull is called only when the consumer requests another chunk. Returning Nothing closes the stream; disconnecting the consumer runs cancel.

Instances

#Route Source

data Route :: forall k. Type -> k -> Type -> Row Type -> Typedata Route method segments request respVariant

Constructors

Instances

#Response Source

data Response :: Row Type -> Type -> Typedata Response headers body

Response data combining headers and body This is a data type (not type alias) to work with type class instances

Constructors

Instances

#PlainText Source

data PlainText

Plain text request/response body (text/plain)

Example: { body :: PlainText }

#PUT Source

data PUT

HTTP PUT method

#POST Source

data POST

HTTP POST method

#PATCH Source

data PATCH

HTTP PATCH method

#NoBody Source

data NoBody

No request body (for GET, DELETE, etc.)

Example: Request {} -- NoBody is the default when body is omitted

#JSON Source

data JSON a

JSON-encoded request body (application/json)

Example: Request { body :: JSON User }

#GET Source

data GET

HTTP GET method

#FormData Source

data FormData a

Form data encoded request body (application/x-www-form-urlencoded)

Example: Request { body :: FormData { username :: String, password :: String } }

#DELETE Source

data DELETE

HTTP DELETE method

#HeaderValue Source

class HeaderValue a  where

Typeclass for values that can be parsed from and printed to HTTP header strings

This mirrors the ParseParam pattern from path parsing and allows headers to be typed beyond just strings.

Returns Either String for detailed error messages (the string is the reason, not the header name).

Examples: parseHeader "42" :: Either String Int = Right 42 parseHeader "bad" :: Either String Int = Left "not a valid integer" printHeader 42 = "42" parseHeader "hello" :: Either String String = Right "hello"

Members

Instances

  • HeaderValue String

    String headers are pass-through (identity)

  • HeaderValue Int

    Integer headers are parsed from strings

  • (HeaderValue a) => HeaderValue (Maybe a)

    Optional headers (Maybe a) where a has HeaderValue This instance allows headers to be optional Note: parseHeader always succeeds for Maybe types (returns Just or Nothing)