Skip to content

Commit

Permalink
Data Layer: Add helper to GET data from generic URL
Browse files Browse the repository at this point in the history
See #28304

In this patch we're adding a small helper to be used to get raw
information from a given URL though a `GET` request.

The way we'd use this is inside of the `waitForData()` function. This is
meant to obscure the global http-data ID so that the user doesn't need
to worry about it.

```js
waitForData( {
	planets: getAtURL( 'https://swapi.co/api/planets/' ),
} ).then( ( { planets } ) => {
	console.log( planets.data );
} );
```
  • Loading branch information
dmsnell committed Nov 26, 2018
1 parent 23336fd commit 29c73c4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions client/state/data-getters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import {
import { convertToSnakeCase } from 'state/data-layer/utils';
import { dummyTaxRate } from 'lib/tax'; // #tax-on-checkout-placeholder

export const getAtURL = url =>
requestHttpData( `get-at-url-${ url }`, rawHttp( { method: 'GET', url } ), {
fromApi: () => data => [ `get-at-url-${ url }`, data ],
} );

export const requestActivityActionTypeCounts = (
siteId,
filter,
Expand Down

0 comments on commit 29c73c4

Please sign in to comment.