Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make response of web api with handler return data optional #2

Open
wants to merge 1 commit into
base: feature/http-verbs
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,15 @@ module.exports = url => {
app.methodToBeUsed(
url,
(req, res) => {
res.send(handler({
const response = handler({
url: req.url,
query: req.query
}));
req: req,
res: res
});

if (response) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand the motivation behind this check. How about ignore the response when not required rather than make this response optional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be times when it will not be a direct returned value that you need to respond to the client, for example when its an async process or when you want to return status codes other than 200.

So this check will see if anything is to be returned, else the called handler function will be responsible to respond.

It may have broken other parts of the code, we will probably need to find a better solution.

res.send(response);
}
}
);
}
Expand Down