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 clientsRowDerive 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 }
#deriveClient Source
deriveClient :: forall @routesRow ctx extraErr clientsRow. DeriveClient ctx extraErr routesRow clientsRow => String -> Record clientsRowDeprecated: 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
deriveClientImpl :: String -> Proxy (Record routesRow) -> Record clientsRow
Instances
(RowToList routesRow rl, DeriveClientRL ctx extraErr rl () clientsRow) => DeriveClient ctx extraErr routesRow clientsRow
#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
deriveClientRL :: String -> Proxy rl -> Record acc -> Record out
Instances
DeriveClientRL ctx extraErr Nil acc acc(IsSymbol label, DeriveClientFn method segments request response ctx extraErr routeErrors result fn, DeriveClientRL ctx extraErr tail acc1 acc2, Cons label fn acc2 out, Lacks label acc2, Cons label (Route method segments request response) routeTail routeRow) => DeriveClientRL ctx extraErr (Cons label (Route method segments request response) tail) acc1 out
#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
deriveClientFn :: String -> Proxy (Route method segments request response) -> fn
Instances
(SegmentPathParams segments pathParams, SegmentQueryParams segments queryParams, ExtractRequestBody request body, ExtractBodyEncoding request encoding, ExtractRequestHeaders request headers, PathPattern segments, BuildUrl segments pathParams queryParams, MakeRequest method, BodyEncoding encoding body, SplitResponses response successRow routeErrors, ParseResponse routeErrors successRow, RowToList successRow successRL, VariantOrValue successRL successRow result, Union pathParams queryParams pathQuery, Nub pathQuery pathQuery, RowToList pathQuery pathQueryRL, RowToList headers headersRL, ToHeaders headersRL headers, CheckBodyIsUnit body bodyFlag, Union routeErrors extraErr errRow, BuildClientFn pathQueryRL headersRL bodyFlag body pathQuery headers (Record pathQuery) (Record ctx) errRow result fn) => DeriveClientFn method segments request response ctx extraErr routeErrors result fn
#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
deriveClientFnWith :: ClientWithConfig ctx extraErr providedHeaders providedQuery -> Proxy (Route method segments request response) -> fn
Instances
(SegmentPathParams segments pathParams, SegmentQueryParams segments queryParams, ExtractRequestBody request body, ExtractBodyEncoding request encoding, ExtractRequestHeaders request headers, PathPattern segments, BuildUrl segments pathParams queryParams, MakeRequest method, BodyEncoding encoding body, SplitResponses response successRow routeErrors, Union pathParams queryParams pathQuery, Nub pathQuery pathQuery, ParseResponse routeErrors successRow, RowToList successRow successRL, VariantOrValue successRL successRow result, Union routeErrors extraErr errRow, Union providedQuery remainingQuery queryParams, Union pathParams remainingQuery callerPathQuery, Nub callerPathQuery callerPathQuery, RowToList callerPathQuery callerPathQueryRL, RowToList headers headersRL, ToHeaders headersRL headers, Union providedHeaders remainingHeaders headers, Nub headers headers, RowToList remainingHeaders remainingHeadersRL, CheckBodyIsUnit body bodyFlag, BuildClientFn callerPathQueryRL remainingHeadersRL bodyFlag body callerPathQuery remainingHeaders (Record callerPathQuery) (Record ctx) errRow result fn) => DeriveClientFnWith method segments request response providedHeaders providedQuery ctx extraErr routeErrors result fn
#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
deriveClientWithImpl :: ClientWithConfig ctx extraErr providedHeaders providedQuery -> Proxy (Record routesRow) -> Record clientsRow
Instances
(RowToList routesRow rl, DeriveClientWithRL providedHeaders providedQuery ctx extraErr rl () clientsRow) => DeriveClientWith providedHeaders providedQuery ctx extraErr routesRow clientsRow
#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
deriveClientWithRL :: ClientWithConfig ctx extraErr providedHeaders providedQuery -> Proxy rl -> Record acc -> Record out
Instances
DeriveClientWithRL providedHeaders providedQuery ctx extraErr Nil acc acc(IsSymbol label, DeriveClientFnWith method segments request response providedHeaders providedQuery ctx extraErr routeErrors result fn, DeriveClientWithRL providedHeaders providedQuery ctx extraErr tail acc1 acc2, Cons label fn acc2 out, Lacks label acc2, Cons label (Route method segments request response) routeTail routeRow) => DeriveClientWithRL providedHeaders providedQuery ctx extraErr (Cons label (Route method segments request response) tail) acc1 out
#ToHeaders Source
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
decodeResponse :: String -> Either String result
Instances
(ReadForeign a) => DecodeResponse a a
#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) resultRe-exports from Yoga.Fetch.Om.StreamDecode
#StreamDecode Source
class StreamDecode a whereMembers
decodeStream :: Strom (Record ()) () Uint8Array -> Strom (Record ()) () a
Instances
Re-exports from Yoga.HTTP.API.Path
#Required Source
data Required aMarker 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
(PathPattern path) => PathPattern (QueryParams path params)
#PathCons Source
data PathCons :: forall k1 k2. k1 -> k2 -> Typedata PathCons left right
Instances
(IsSymbol s, PathPatternSegs rest) => PathPatternSegs (PathCons (Lit s) rest)(IsSymbol name, PathPatternSegs rest) => PathPatternSegs (PathCons (Capture name ty) rest)(IsSymbol name, PathPatternSegs rest) => PathPatternSegs (PathCons (Param name ty) rest)(IsSymbol s, PathPatternSegs rest) => PathPatternSegs (PathCons s rest)(IsSymbol s, ParsePath (Path rest) params) => ParsePath (Path (PathCons (Lit s) rest)) params(IsSymbol name, ParseParam ty, ParsePath (Path rest) restParams, Cons name ty restParams fullParams, Lacks name restParams) => ParsePath (Path (PathCons (Capture name ty) rest)) fullParams
#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
(PathPatternSegs segs) => PathPattern (Path segs)(PathPatternSegs segs) => PathPatternSegs (Path segs)ParsePath (Path Root) ()(IsSymbol s) => ParsePath (Path (Lit s)) ()(IsSymbol name, ParseParam ty, Cons name ty () params, Lacks name ()) => ParsePath (Path (Capture name ty)) params(IsSymbol s, ParsePath (Path rest) params) => ParsePath (Path (PathCons (Lit s) rest)) params(IsSymbol name, ParseParam ty, ParsePath (Path rest) restParams, Cons name ty restParams fullParams, Lacks name restParams) => ParsePath (Path (PathCons (Capture name ty) rest)) fullParams
#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
(IsSymbol name) => PathPatternSegs (Param name ty)(IsSymbol name, PathPatternSegs rest) => PathPatternSegs (PathCons (Param name ty) rest)
#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
(IsSymbol name) => PathPatternSegs (Capture name ty)(IsSymbol name, PathPatternSegs rest) => PathPatternSegs (PathCons (Capture name ty) rest)(IsSymbol name, ParseParam ty, Cons name ty () params, Lacks name ()) => ParsePath (Path (Capture name ty)) params(IsSymbol name, ParseParam ty, ParsePath (Path rest) restParams, Cons name ty restParams fullParams, Lacks name restParams) => ParsePath (Path (PathCons (Capture name ty) rest)) fullParams
#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
(PathPattern path) => PathPattern (QueryParams path params)(PathPatternSegs segs) => PathPattern (Path segs)(PathPatternSegs segs) => PathPattern segs
#type (:?) Source
Operator alias for Yoga.HTTP.API.Path.QueryParams (left-associative / precedence 1)
#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 t0A 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
(RenderMethod method, PathPattern segments, DefaultRequestFields partialRequest reqHeaders reqCookies encoding, RenderHeadersSchema reqHeaders, RenderCookieParamsSchema reqCookies, DetectSecurity reqHeaders, DetectCookieSecurity reqCookies, SegmentPathParams segments pathParams, RenderPathParamsSchema pathParams, SegmentQueryParams segments queryParams, RenderQueryParamsSchema queryParams, RenderRequestBodySchema encoding, RowToList userResp rl, RenderVariantResponseSchemaRL rl, HasOperationMetadata (Route method segments (Record partialRequest) userResp)) => ToOpenAPI (Route method segments (Record partialRequest) userResp)(ToOpenAPI (Route method segments (Record partialRequest) userResp)) => ToOpenAPI (Route method segments (Request (Record partialRequest)) userResp)(RenderMethod method, PathPattern segments, ToOpenAPI (Route method segments request resp)) => CollectOperations (Route method segments request resp)(DefaultRequestFields partialRequest reqHeaders reqCookies encoding, CollectSchemas encoding, RowToList userResp rl, CollectVariantSchemasRL rl) => CollectRouteSchemas (Route method segments (Record partialRequest) userResp)(CollectRouteSchemas (Route method segments (Record partialRequest) userResp)) => CollectRouteSchemas (Route method segments (Request (Record partialRequest)) userResp)(DefaultRequestFields partialRequest reqHeaders reqCookies encoding, CollectSchemaNames encoding reqNames, RowToList userResp rl, CollectVariantSchemaNames rl respNames, Union reqNames respNames names) => CollectRouteSchemaNames (Route method segments (Record partialRequest) userResp) names(CollectRouteSchemaNames (Route method segments (Record partialRequest) userResp) names) => CollectRouteSchemaNames (Route method segments (Request (Record partialRequest)) userResp) names
#NoBody Source
data NoBodyNo request body (for GET, DELETE, etc.)
Example: Request {} -- NoBody is the default when body is omitted
#FormData Source
data FormData aForm data encoded request body (application/x-www-form-urlencoded)
Example: Request { body :: FormData { username :: String, password :: String } }
#HeaderValue Source
class HeaderValue a whereTypeclass 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
printHeader :: a -> String
Instances
HeaderValue StringHeaderValue IntInteger 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)
- Modules
- Yoga.
Fetch. Om - Yoga.
Fetch. Om. BuildUrl - Yoga.
Fetch. Om. ClientFunction - Yoga.
Fetch. Om. ExtractParams - Yoga.
Fetch. Om. MakeRequest - Yoga.
Fetch. Om. ParseResponse - Yoga.
Fetch. Om. ReadOptional - Yoga.
Fetch. Om. Simple - Yoga.
Fetch. Om. SplitParams - Yoga.
Fetch. Om. SplitResponses - Yoga.
Fetch. Om. StreamDecode - Yoga.
Fetch. Om. Variant
String headers are pass-through (identity)