Skip to content

Instantly share code, notes, and snippets.

@joedski
Last active September 19, 2017 02:28
Show Gist options
  • Save joedski/a6bd473a31bddfcf4a3e57f99a1df663 to your computer and use it in GitHub Desktop.
Save joedski/a6bd473a31bddfcf4a3e57f99a1df663 to your computer and use it in GitHub Desktop.
hof thunks: simple endpoint example
import { resource } from 'my-app/api/resource';
export const myEndpoint = resource('myEndpoint', (params, meta) => ({
uri: `myservice.example.com/v1/my-endpoint?${querystring.stringify(params)}`,
headers: DEFAULT_HEADERS,
// ...etc.
}));
// Or, even better:
import { resource } from 'my-app/api/resource';
import * as req from 'my-app/api/request-utils';
export const myEndpoint = resource('myEndpoint', compose(
req.method('GET'),
req.uri((params) => `myservice.example.com/v1/my-endpoint?${querystring.stringify(params)}`),
req.withDefaultHeaders,
// ...etc.
));
// How this is accomplished is left as an exercise to the reader.
// Remember that in `resource`, it expects `mapArgs` to return an object with `uri` and `options`...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment