Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

best practice for custom http responses #3994

Closed
TomerSalton opened this issue Oct 24, 2019 · 4 comments
Closed

best practice for custom http responses #3994

TomerSalton opened this issue Oct 24, 2019 · 4 comments
Assignees
Labels

Comments

@TomerSalton
Copy link

Hey,

I want to change the HTTP response (both errors and message) that is returned by the server.
Two examples:

  1. If a user tries to send a PUT request in order to create an item, I want to return him a "ERROR 501 Not Implemented" response.
  2. If a user sends a POST request that requires a lot of processing power, I want to return HTTP 202 (Created).

Would you be able to provide me the best practice of implementing those HTTP responses customizations?

Thanks alot for your help,
Tomer.

@dhmlau
Copy link
Member

dhmlau commented Oct 24, 2019

@TomerSalton, do you mean to change the HTTP response outside the controller?
If yes, could you please take a look at the discussion thread in #1867? especially this comment and this comment. Thanks.

@achrinza
Copy link
Member

achrinza commented Nov 6, 2019

Is there any plan to do first-class support on custom HTTP response (not just error-handling)?

I've followed the solution on StackOverflow. However, this meant that the repository now expects an @loopback/rest.Response, on which how to mock is not documented.

Otherwise, is there a way to create controller unit tests?

@raymondfeng
Copy link
Contributor

@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.

@stale stale bot added the stale label Dec 25, 2020
@bajtos bajtos closed this as completed Mar 11, 2021
@loopbackio loopbackio locked and limited conversation to collaborators Mar 11, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

5 participants