purescript-contrib/purescript-affjax

Requestable instance for Foreign

purefn opened this issue · 6 comments

Is there a reason why there isn't a Requestable Foreign instance? Or, perhaps RequestContent could be a type alias for Foreign just like ResponseContent is?

I wasn't sure exactly what you were getting at with the question, so I tried to answer it two ways, hopefully it makes sense. :)

One of the outstanding things to look at is to add a mime type to Requestable for setting the Content-Type header (#8). Providing a Foreign instance then would be problematic, as it can be basically anything. There area only a few acceptable types of content for sending via XHR, so using Foreign for RequestContent would give a misleading impression.

The Foreign instance for ResponseContent is specifically for JSON responses, it doesn't cover the other cases. There's no corresponding requestable Foreign instance for JSON values, as it isn't a valid type to send via XHR - it needs to be stringifyed first.

The Foreign instance for ResponseContent

That should probably change. Instead add a ResponseContent instance for Argonaut's Json type. Then there could be symmetry with Request.

I kinda wanted to avoid bringing Argonaut in, as it's pretty hefty, especially since you can use Foreign to similar effect.

A JsonContent newtype over Foreign perhaps?

Hmm, let's break out Argonaut into argonaut-core, argonaut-combinators, argonaut-serialization, etc.

argonaut-core could contain nothing except: Json data type, printing, and parsing (i.e. just a few lines of code). The serialization (type class + instances) could go into serialization.

👍 works for me.

There's no longer a Requestable as of Affjax v6.0.0, so this can be closed.