Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import superagentPromise from 'superagent-promise';
- import _superagent from 'superagent';
- // http client
- const superagent = superagentPromise(_superagent, global.Promise);
- // root api url
- const API_ROOT = 'https://conduit.productionready.io/api';
- // callback to extract the body out of a response
- const responseBody = res => res.body;
- // http method wrapppers
- // make a request to the given url and parse out the body
- const requests = {
- get: url =>
- superagent.get(`${API_ROOT}${url}`).then(responseBody),
- post: (url, body) =>
- superagent.post(`${API_ROOT}${url}`).then(responseBody)
- };
- // articles methods
- const Articles = {
- // get promise for 10 articles
- all: page =>
- requests.get('/articles?limit=10')
- };
- const Auth = {
- // get promise for login success/failure
- login: (email, password) =>
- requests.post('/users/login', { user: { email, password } })
- };
- export default {
- Articles,
- Auth
- };
Advertisement
Add Comment
Please, Sign In to add comment