-
Notifications
You must be signed in to change notification settings - Fork 0
Response
Mathias Quintero edited this page Mar 18, 2016
·
1 revision
Just like with the Requests, you also get special Response objects with their only simplifications.
There are many ways you can quickly respond. Status and headers are always optional and the defaults will be used if you don't specify them.
var myObject = {
name: "My Object",
id: 42
};
response.respondJSON(myObject);
Or if you want to include more information like the header:
var headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
}
response.respondJSON(myObject, 201, headers);
The same goes for when responding only with text:
response.respondPlainText("This is my response: 42");
Simply call the function with the path to the file. You are not allowed to put your own headers on this one.
response.respondFile("path/to/file.ext");
If you think the user forgot to put the auth info on there request you can prompt them again:
response.promptPassword("Please Enter a Password");
You can also simply redirect the user to another place with, for example:
response.redirect("http://www.google.com");
We can also give you the regular response object that if you need something more tailored or down at the metal.
var res = response.getResponseObject();