Module

Yoga.Fetch.Om

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

#client Source

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

Derive API client functions from route definitions using VTA

type UserAPI = { getUser :: Route ... }
api = client @UserAPI "https://api.example.com"

#deriveClient Source

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

Deprecated: Use client with VTA instead

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

#DeriveClient Source

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

Members

Instances

#DeriveClientRL Source

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

Members

Instances

#DeriveClientFn Source

class DeriveClientFn :: forall k1. Type -> k1 -> Type -> Row Type -> Row Type -> Row Type -> Type -> Type -> Constraintclass DeriveClientFn method segments request response routeErrors successRow result fn | method segments request response -> routeErrors successRow result fn 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 a

Streaming response body (returns a Strom of decoded chunks)

Example: { body :: Streaming Uint8Array } -- raw binary { body :: Streaming String } -- text

#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