workco/marvin

Add example of post (api) request

Closed this issue · 2 comments

Hi all. Great work! Would it be possible to include an example of how you handle post requests with this setup? If you can find the time to add an example that would be great. If not, no worries, excellent work one way or the other. Saved me a lot of time. Keep up the good work!!!

Hello @leonardreidy,

Marvin includes example of async redux actions here:
https://github.com/workco/marvin/blob/master/source/js/actions/app.js

Only difference would be in your api call in this file
https://github.com/workco/marvin/blob/master/source/js/api/index.js

Change it to something like this:

import 'es6-promise';

function testAsync() {
  return fetch('https://api.github.com/orgs/octokit/repos', {})
    .then(response => {
      return response.text();
    });
}

export default {
  testAsync,
};

This is very simplified example which returns text instead of JSON and without error handling, but I hope you get the idea.

EDIT: Actually it makes sense to use real API call instead of mocked async request. I'll add that with the new version, I'm working on a major update.