Skip to content

Commit 9a68713

Browse files
committed
Data Layer: Add helper to GET data from generic URL
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 ); } ); ```
1 parent 046076f commit 9a68713

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

client/state/data-getters/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import {
2323
import { convertToSnakeCase } from 'state/data-layer/utils';
2424
import { dummyTaxRate } from 'lib/tax'; // #tax-on-checkout-placeholder
2525

26+
export const getAtURL = url =>
27+
requestHttpData( `get-at-url-${ url }`, rawHttp( { method: 'GET', url } ), {
28+
fromApi: () => data => [ `get-at-url-${ url }`, data ],
29+
} );
30+
2631
export const requestActivityActionTypeCounts = (
2732
siteId,
2833
filter,

0 commit comments

Comments
 (0)