简体   繁体   中英

How to set http response code in Parse Server cloud function?

A parse server cloud function is defined via

Parse.Cloud.define("hello", function(request, response) {..});

on the response, I can call response.success(X) and response.error(Y) , and that sets the http response code and the body of the response.

But how do I define a different code, like created (201)? And how do I set the headers of the response?

thanks, Tim

You are allowed to return any valid JSON from response.success() . Therefore, you could create an object with fields such as code , message , and value , so you can set the code, give it a string descriptor, and pass back the value you normally would, if there is one. This seems to accomplish what you need, though you will have to keep track of those codes across your platforms. I recommend looking up standard http response codes and make sure you don't overlap with any standards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM