Skip to content

Instantly share code, notes, and snippets.

@thiagovilla
Last active August 22, 2018 20:07
Show Gist options
  • Save thiagovilla/4ad34a06c76cd80b4d28519b695123a8 to your computer and use it in GitHub Desktop.
Save thiagovilla/4ad34a06c76cd80b4d28519b695123a8 to your computer and use it in GitHub Desktop.
Function-based GET endpoint with RESTful params object
// api/orders.js
import api from './api'
// 'sanitize' function here
const getOrders = ({ offset = 0, limit = 25, query = '', ...otherParams }) =>
api.get(`/orders?offset=${offset}&limit=${limit}&query=${query}`)
.then(response => ({
items: response.data.results.map(sanitize),
count: response.data.count
}))
.catch(error => { throw Error(error) })
// other endpoints (getOrder, addOrder etc.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment