Decoding body response from azure functions

I am trying to perform azure functions. I understood the work of azure functions and the necessary bindings for combining functions with other azure services.

Scenario:

Posting JSON through the body of the request for azure functions. Store the JSON in the DB document and return the same JSON as the response.

It works correctly when calling api in the azure console. And he also works at a postman. But strangely, this does not work in my application.

Problem: response in response app

In the above image, as you can see, the response is returned by the azure functions in the reaction application. But the body is a ReadableStream object. There is also a property locked . I tried using the authorization level . . .

:

. , . ?

(POST) Azure

DB . :

module.exports = function(context, req) {
    context.log('Node.js HTTP trigger function processed a request. RequestUri=%s', req.originalUrl);

    if (req.query.name || (req.body)) {
        let eventId = req.body.eventId;
        let name = req.body.name;
        let purpose = req.body.purpose;
        let dateArray = req.body.dateArray;
        let location = req.body.location;

        let eventObj = {
            "id": eventId,
            "name" : name,
            "purpose" : purpose,
            "dateArray": dateArray,
            "location": location,
            "attendees": []
        }

        context.bindings.outputDocument = eventObj;
        context.res = {
            // status: 200, /* Defaults to 200 */
            body: eventObj
        };
    }
    else {
        context.res = {
            status: 400,
            body: "Please pass a name on the query string or in the request body"
        };
    }
    context.done();
};

( )

response-redux. POSTing to azure . . , . http-, , .

export function registerEvent(eventId, name, purpose, dateArray, location, attendees) {
  return dispatch => {
    return fetch('https://letsmeetup-test1.azurewebsites.net/api/HttpTriggerNodeJS2', {credentials: 'omit',
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({'eventId': eventId, 'name' : name, 'purpose' : purpose, 'dateArray': dateArray, 'location': location, 'attendees': attendees})})
      .then(res => {
        if (res.status !== 200) {
          let status = res.status;
          console.log('error in posting event');
        }
        console.log("printing response from azure functions");
        console.log(res);
        return res.json();
      })
      .then(json => storeEventId(json))
  };
}
0

All Articles