Commit graph

45 commits

Author SHA1 Message Date
Gabriel Aumala
c075ac7b49 docs: improve m.request return value description
In the m.request return value description, add a line informing that
error status codes cause the promise to reject.
2022-01-25 23:07:51 +01:00
Gustavo Rodrigues
ddb3d4ab07 Update fetch() browser support in docs (#2522)
* Update fetch() browser support in docs

As https://caniuse.com/#feat=fetch shows it's supported since Safari 10.1.

* Update docs/request.md

Co-Authored-By: Isiah Meadows <contact@isiahmeadows.com>

[skip ci]
2019-08-30 08:55:32 -04:00
Isiah Meadows
8eed896859
Track XHR replacements correctly (#2455)
* Track XHR replacements correctly

Fixes #2439

* Update docs [skip ci]
2019-07-05 19:50:51 -04:00
Woody Gilk
6f602de878 Improve initial request docs example (#2430) 2019-06-12 05:53:59 -04:00
Erik Vullings
8a7eae00ed Fix for #2423. request.data => body, params is used for querystrings (#2425)
* Fix for #2423. request.data is replaced by body, params is used for querystring interpolation.

* Updated documentation after code review by shadowhand and isiahmeadows

* Convert indentation to tabs

* Replacing m.request.data and m.jsonp.data with params or body.

* Update request.md


Co-authored-by: Isiah Meadows <contact@isiahmeadows.com>
2019-06-10 19:36:32 -04:00
Isiah Meadows
794e8e963f
Bring some sanity to request parsing and error handling (#2335)
* Update docs/request.md
* Bring some sanity to request parsing and error handling

- The browser can do JSON parsing itself. Let's defer to that where
  possible. (A few IE hacks are required here, though.)
- Don't propagate any error that occurs before `deserialize`/`extract`.
- Allow sending raw array buffers/blobs/etc. to `deserialize`.
- Align behavior more closely with the XHR spec.
- Send the more useful parsed response to `deserialize`, not the less
  useful string response.
2019-05-29 09:41:22 -04:00
Isiah Meadows
58f1c74394
Streamline route/request path handling and split params + body in requests (#2361)
Fixes #2360
Fixes #1138
Fixes #1788 a little less hackishly
Probably fixes a few other issues I'm not aware of.

This more or less goes with @lhorie's comment here, just with a minor name
change from `query` to `params`:

https://github.com/MithrilJS/mithril.js/issues/1138#issuecomment-231363395

Specifically, here's what this patch entails:

- I changed `data` and `useBody` to `params` and `body` in `m.request`.
  Migration is trivial: just use `params` or `body` depending on which you
  intend to send. Most servers do actually care where the data goes, so you can
  generally pretty easily translate this accordingly. If you *really* need the
  old behavior, pass the old value in `params` and if `method === "GET"` or
  `method === "TRACE"`, also in `body`.
- I opened up all methods to have request bodies.
- I fixed `m.parseQueryString` to prefer later values over earlier values and
  to ensure that objects and arrays are persisted across both hash and query
  param parsing. That method also accepts an existing key/value map to append
  to, to simplify deduplication.
- I normalized path interpolation to be identical between routes and requests.
- I no longer include interpolated values in query strings. If you need to
  duplicate values again, rename the interpolation to be a distinct property
  and pass the value you want to duplicate as it.
- I converted `m.route` to use pre-compiled routes instead of its existing
  system of dynamic runtime checking. This shouldn't have a major effect on
  performance short-term, but it'll ease the migration to built-in userland
  components and make it a little easier to reconcile. It'll also come handy
  for large numbers of routes.
- I added support for matching routes like `"/:file.:ext"` or
  `"/:lang-:region"`, giving each defined semantics.
- I added support for matching against routes with static query strings, such
  as `"/edit?type=image": { ... }`.
- I'm throwing a few new informative errors.
- And I've updated the docs accordingly.

I also made a few drive-by edits:

- I fixed a bug in the `Stream.HALT` warning where it warned all but the first
  usage when the intent was to warn only on first use.
- Some of the tests were erroneously using `Stream.HALT` when they should've
  been using `Stream.SKIP`. I've fixed the tests to only test that
  `Stream.HALT === Stream.SKIP` and that it only warns on first use.
- The `m.request` and `m.jsonp` docs signatures were improved to more clearly
  explain how `m.request(url, options?)` and `m.jsonp(url, options?)` translate
  to `m.request(options)` and `m.jsonp(options)` respectively.

-----

There is some justification to these changes:

- In general, it matters surprisingly more than you would expect how things
  translate to HTTP requests. So the comment there suggesting a thing that
  papers over the difference has led to plenty of confusion in both Gitter and
  in GitHub issues.

- A lot of servers expect a GET with a body and no parameters, and leaving
  `m.request` open to working with that makes it much more flexible.

- Sometimes, servers expect a POST with query parameters *instead* of a JSON
  object. I've seen this quite a bit, even with more popular REST APIs like
  Stack Overflow's.

- I've encountered a few servers that expect both parameters and a body, each
  with distinct semantic meaning, so the separation makes it much easier to
  translate into a request.

- Most of the time, path segments are treated individually, and URL-escaping
  the contents is much less error-prone. It also avoids being potentially
  lossy, and when the variable in question isn't trusted, escaping the path
  segment enables you to pass it through the URL and not risk being redirected
  to unexpected locations, avoiding some risks of vulnerabilities and client
  side crashes.

If you really don't care how the template and parameters translate to an
eventual URL, just pass the same object for the `params` and `body` and use
`:param...` for each segment. Either way, the more explicit nature should help
a lot in making the intent clearer, whether you care or not.
2019-05-29 09:28:40 -04:00
Ayush Jain
982fdf5737 Corrected the case issue of 'JavaScript' throughout the docs (#2401)
* corrected JavaScript spelling
2019-04-01 08:14:38 -04:00
Isiah Meadows
a96caf25c5
Fix #1908, document fields. [skip ci] (#2314) 2018-11-27 18:02:08 -05:00
Stephan Hoyer
af90b6b4a6 Add support for setting responseType of xhr via m.request options 2018-08-20 11:29:36 +02:00
Stephan Hoyer
d50d53f31d feat: Add support for timeout to m.request (#1966) 2017-11-14 14:47:01 -08:00
spacejack
80b6a1af0d feat: Don't reject m.request Promise if extract callback supplied (#2006) 2017-11-13 08:08:54 -08:00
theRefugee
9b6ec10a93 Update request.md 2017-07-12 15:20:43 +02:00
Scotty Simpson
dfcbc8e2b3 docs: Update request.md (#1851) 2017-05-12 09:40:28 -07:00
Kevin Cameron
e966025171 Correct example code 2017-05-01 22:54:05 -07:00
spacejack
5229b0bc93 docs: Fix extract siguature, clarify deserialize & extract descriptions. (#1729) 2017-03-21 10:59:44 -07:00
Patrik Johnson
d63a88618e Rewrite docs clarity (#1534)
* Add a few words and bits for clarity and better text flow in the rewrite docs
* Rephrase some helpful wording
2017-01-11 15:57:14 -08:00
impinball
95d738bc71 Add support for options.headers in m.request + tests/docs
I also had to edit the mocks accordingly, so I could inspect the headers set.
2016-12-30 02:52:00 -05:00
Leo Horie
ae916664de tweaks to docs 2016-12-07 10:09:49 -05:00
Leo Horie
50d727d017 lint docs 2016-12-02 21:19:19 -05:00
Leo Horie
cdb9017a72 update docs, add descriptions for api methods 2016-12-02 17:51:07 -05:00
Leo Horie
9f6a1086e4 Merge remote-tracking branch 'origin/rewrite' into rewrite
# Conflicts:
#	mithril.min.js
2016-12-01 01:50:12 -05:00
Leo Horie
87dcbbf5c7 small tweaks to docs 2016-12-01 01:49:19 -05:00
Jeff
e76bb96787 Add link to response detail section (#1434) 2016-11-28 11:43:29 -08:00
Leo Horie
d1c2a44de8 add withCredentials option in m.request 2016-11-23 01:35:56 -05:00
spacejack
eb2f24e3b3 Add note about JSON parsing behaviour with extract callback 2016-11-17 14:07:20 -05:00
Leo Horie
6ce2a384ec simplify streams, lint docs 2016-11-15 23:13:38 -05:00
Leo Horie
a7f8018df9 fix typo 2016-11-15 10:40:42 -05:00
Pat Cavit
8388cedad8 .items -> .list 2016-11-14 10:09:23 -08:00
Pat Cavit
647877958c .items -> .list 2016-11-14 10:08:23 -08:00
Leo Horie
4b061dacfe Merge remote-tracking branch 'origin/rewrite' into rewrite
# Conflicts:
#	mithril.js
#	mithril.min.js
2016-11-13 22:45:28 -05:00
Leo Horie
bc8cf4ed76 change m.request return value from stream to promise
remove m.prop
add m.Promise
update tests and examples
2016-11-13 22:44:22 -05:00
Barney Carroll
0fad68fa69 Method defaults to GET as of #1393 (#1394) 2016-11-12 14:12:03 -08:00
Leo Horie
2ed7184012 document optional url arg in request 2016-11-11 18:20:42 -05:00
Leo Horie
6514a38162 document querystring apis 2016-10-18 10:16:20 -04:00
Patrik Johnson
88e7cf5454 Rewrite: ignore m.request deserialize option if extract is passed 2016-08-04 19:19:12 +03:00
Leo Horie
726b79a18d document multi-upload 2016-07-28 22:40:46 -04:00
Leo Horie
ab6cc583f2 more docs for m.request 2016-07-27 00:14:47 -04:00
Leo Horie
c196b8b475 fix loading/error example, beef up render docs 2016-07-12 00:34:56 -04:00
Leo Horie
b3d784d841 fix example 2016-07-11 09:31:56 -04:00
Leo Horie
7318a0d88b update docs re: component anti-patterns, lint docs 2016-07-07 13:23:16 -04:00
Leo Horie
015a812610 fantasy-land methods no longer absorb streams 2016-06-30 01:28:50 -04:00
Leo Horie
7fa3fee9ce improve docs for m.request 2016-06-24 23:41:35 -04:00
Barney Carroll
af49a7dcb4 Long-term Node fans might take exception (lol)...
...to saying there aren't *any* mechanisms for error-handling in callback-centric async APIs
2016-06-21 10:09:59 +01:00
Leo Horie
5e3e984152 request docs wip 2016-06-20 09:22:52 -04:00