Skip to content

API discussion #1

@jdegoes

Description

@jdegoes

A ticket to discuss the API.

The other day I was thinking something like this could work:

ajax :: forall e. AjaxRequest -> Aff (ajax :: AJAX | e) AjaxResponse

type AjaxRequest = {
  url :: String,
  method :: Method,
  headers :: StrMap String,
  content :: Content,
  ...
}

type AjaxResponse = {
  headers :: StrMap String
  ...
}

ajaxRequestDefaults :: String -> AjaxRequest

Then a separate module could define combinators, such as:

GET :: AjaxRequest -> AjaxRequest

contentType :: MimeType -> AjaxRequest -> AjaxRequest
...
runAjax :: String -> (AjaxRequest -> AjaxRequest) -> Aff (ajax :: AJAX | e) AjaxResponse
runAjax url f = ajax (f (ajaxRequestDefaults url))

So you'd write code like:

runAjax "http://foo.com" $ GET >>> contentType applicationJson

But I'm sure there are better APIs. Let's discuss here if you have any ideas.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions