feat #22: New invoke syntax proposal #23
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Closes #22
What is the current behavior?
The
invoke()
function currently implements the following behavior:fetch()
function. This obliges the user to write significant amounts of boilerplate code (e.g. to JSON.parse() the body or set the right headers), as described in issue Callinginvoke
via Android OS without specifyingcontent-type
header results in a failed request #14{ data, error }
object wheredata
has already been automagically de-serialized. However the richer underlyingResponse
object from thefetch()
call is lost (e.g. status code, headers, etc.), as described in issue shouldThrowOnError does not apply to functions.invoke() #20What is the new behavior?
The new behavior modifies the prototype of
invoke()
in accordance with the proposal set out under feature request #22 :invoke
function automagically serializes the body and sets the headers. This reduces the amount of boilerplate for the most common input data typesResponse
object can now be accessed via a thirdoptions
parameter, which provides callback entry points to thefetch()
call.Please refer to the accompanying README.md file for further details on the new proposed behavior of
invoke
.Additional context
This PR closes #22.
It also fixes #20 and fixes #14.
Notes:
Fetch
,Request
, andResponse
Web APIs. Previous options that used to be passed as named parameters are now passed according to the prototypes of these APIs.request
headers are written according to the data type on the way out, and the incoming data type is inferred from reading theresponse
headers on the way back. This is an opinionated convention which I believe covers 99.9% of the use cases of a serverlessfetch()
functionality.