-
Notifications
You must be signed in to change notification settings - Fork 73
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
Defining multiple responses #15
Comments
|
The framework is based on a few opinionated choices. The way we use it, the view function can only return the "normal" response, the one for which the status code is specified in the Then there can be errors that interrupt the normal flow and generate an Indeed, you can document other responses using However, calling twice the So you can document the two error codes using What is your use case? I suppose you're allowing PUT to create entities. Whether this is good practice is debated AFAIK. This is not something we do so we never tried to support it. We only use POST to create and PUT to update. |
Yeah, it's been a pleasure to use it. This is just an edge case. What I'm doing may not be considered strictly restful. My resource is a list of strings. Posting a list of strings once to
It's actually success codes. I just decorate my view with
Cool! I would have liked another decorator that takes the same args as |
Yes, this is not the common case. I won't comment on restfulness. What happens if you GET I have more or less similar case in an app and I use PATCH and return 204 because I don't return the result.
I understand. What I meant is that I stick to the "only one possible successful code" approach and I'd like to add better means to document error codes.
OK, I get it. But then you're far off beaten paths. It works but not using
It's not really the direction I'd like to take. I'd like to keep the doc inferred from the code as much as possible. When needed, use Regarding mimetype, I suppose you're referring to |
It'll be a 404.
Sure. I guess the alternative is post If you want to force users to have a single success response, then I'll accept it. Regarding far off beaten paths and mimetypes, I have another view that responds with an image, where I'm also using not using
I saw no other way to do it right now. |
I'm open to changes. It's a tradeoff between relevance of the use case and difficulty of the change. I don't see any easy way to change that. Regarding the mime types, I was thinking of a way to globally replace the serializer, for instance to replace json with XML. This is easy, but making the doc consistent revealed more complicated than I thought. I think you did the right thing about the image use case. Improving |
Yeah, it seems to be very tricky. Maybe you can check (in the response-wrapper) if the view returned a flask response, and if so, skip serialization. That could be a way for users to override the serializer at the resource level, atleast until there is another way to do it. Just to clarify:
I guess you'd would have a mapping from mimetype to serialization function to make it proper. |
I'd like to define multiple response codes for a view (201 for created, 200 for updated).
It seems that decorating a view twice will always return 200:
Is there a way around this?
Thanks
The text was updated successfully, but these errors were encountered: