Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new topic for the Peregrine REST API client #259

Merged
merged 4 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make changes based on PR feedback
  • Loading branch information
jcalcaben committed Sep 18, 2018
commit 25bac9864453740218a1d5cf08a9202d62fbf38f
13 changes: 8 additions & 5 deletions packages/pwa-devdocs/src/_data/peregrine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ entries:
- label: Overview
url: /peregrine/

- label: Components
- label: Utility modules
entries:

- label: REST API client
url: /peregrine/reference/rest-api-client/

- label: React components
entries:

- label: ContainerChild
Expand All @@ -18,8 +24,5 @@ entries:
- label: List
url: /peregrine/reference/list/

- label: REST API client
url: /peregrine/reference/rest-api-client/

- label: Router
url: /peregrine/reference/router/
url: /peregrine/reference/router/
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: REST API client
---

The REST API client component provided by Peregrine allows you to work with non-GraphQL web APIs.
The REST API client utility module provided by Peregrine allows you to work with non-GraphQL web APIs.
The default implementation is a client that works with the REST API for Magento 2.3 and above.

## Magento 2 REST API client
Expand All @@ -12,7 +12,7 @@ This function is similar to the Web standard [`fetch()`][] function with a few d
It also contains features to support [multicasting][] and [rolling requests][].

For basic use cases, use the `request()` method.
For more advanced cases, use the [`Magento2ApiRequest`][] class, which the `request()` method wraps.
For more advanced cases, use the [`M2ApiRequest`][] class, which the `request()` method wraps.

### Syntax

Expand Down Expand Up @@ -98,7 +98,7 @@ request(

### Error handling

Promoises returned by `request()` are rejected if the server responds with an HTTP error code within the 4xx-5xx range.
Promises returned by `request()` are rejected if the server responds with an HTTP error code within the 4xx-5xx range.
This is different from the standard `fetch()` behavior, which ignores HTTP errors so it can resolve the promise and only fails on network connectivity errors.

The Magento REST API uses HTTP error codes to denote failed operations, so
Expand Down Expand Up @@ -151,12 +151,12 @@ This feature has no effect on non-multicast requests.

To use a rolling request, set the `cache` configuration option to `reload` or `no-store`.

### The `Magento2ApiRequest` class
### The `M2ApiRequest` class

The `request()` method is a convenience wrapper on top of the
`Magento2ApiRequest` class.
`M2ApiRequest` class.

Use the `Magento2ApiRequest` class if you want more control over your REST requests.
Use the `M2ApiRequest` class if you want more control over your REST requests.

```js
import { RestApi } from '@magento/peregrine';
Expand All @@ -181,7 +181,7 @@ function placeCancelable(emitter) {

`new M2ApiRequest(resourceUrl, opts)`

: Creates a new `Magento2ApiRequest` class to a specific `resourceUrl` using the configuration values in `opts`.
: Creates a new `M2ApiRequest` class to a specific `resourceUrl` using the configuration values in `opts`.
See `request()` method [parameters][].

`run()`
Expand Down Expand Up @@ -221,5 +221,5 @@ function placeCancelable(emitter) {
[Magento REST endpoint]: https://devdocs.magento.com/guides/v2.3/rest/list.html
[fetch options]: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters
[`UVString`]: https://developer.mozilla.org/en-US/docs/Web/API/USVString
[`Magento2ApiRequest`]: #the-magento2apirequest-class
[parameters]: #parameters
[`M2ApiRequest`]: #the-m2apirequest-class
[parameters]: #parameters