Last active
August 22, 2018 20:07
-
-
Save thiagovilla/4ad34a06c76cd80b4d28519b695123a8 to your computer and use it in GitHub Desktop.
Function-based GET endpoint with RESTful params object
This file contains 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
// 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