Last active
September 19, 2017 02:28
-
-
Save joedski/a6bd473a31bddfcf4a3e57f99a1df663 to your computer and use it in GitHub Desktop.
hof thunks: simple endpoint example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
})); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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