Constructor
# new module:APIResp(codeopt)
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
code |
Number
|
<optional> |
The HTTP code of the response |
Example
const response = new APIResp(200).setMessage("Logged in!").setData({ user: {firstName: "Hammong", lastName: "Gus"} });
const json = response.toJSON();
console.log(json); // ->
// {
// code: 200,
// message: "Logged in!",
// data: {
// firstName: "Hammong",
// lastName: "Gus"
// }
// }
Members
Methods
# setCode(code) → {APIResp}
Changes the HTTP response code
Parameters:
| Name | Type | Description |
|---|---|---|
code |
Number
|
The HTTP code of the response |
APIResp
# setMessage(message) → {APIResp}
Changes the response message
Parameters:
| Name | Type | Description |
|---|---|---|
message |
string
|
null
|
The response message |
APIResp
# toJSON() → {Object.<string, *>}
Create an object with the values of this instance
Object.<string, *>