yunard
yunard

Reputation: 43

Call API resource using meteor

I would like to call an API resource using meteor and React. What I would like to happen is;

  1. load a page
  2. have a form shown to a user
  3. user submits form
  4. use the form data as parameters for the API call via POST
  5. returns the API response to React.

How do I achieve this? Am I on the right track by using Meteor.wrapAsync?

Upvotes: 0

Views: 96

Answers (1)

DTul
DTul

Reputation: 679

Meteor.wrapAsync wouldn't be neccesary. If you have a button in React. You should keep the fields in the state. React Forms. Then use this code in your component to call a meteor method.

onClick(e){
  e.preventDefault();
  const { objectToPost } = this.state;
  Meteor.call("some_method", objectToPost, (err, res) => { doSmthWithFrontend });
}

The Meteor method will be called async for you and return when the call returns. In this method you can use Meteor Http to achieve what you want.

Upvotes: 1

Related Questions