librelist archives

« back to archive

Simple proposal regard HTTP status codes

Simple proposal regard HTTP status codes

From:
Daniele Nicolodi
Date:
2011-07-26 @ 20:36
Hello,

I always find myself wondering which is the correct numeric HTTP status
code I should use with the Flask abort() function. Would it make sense
to have a few constants defined somewhere in the Flask namespace, like

NOT_AUTHORIZED = 403
NOT_FOUND = 404
...

and so on? Are those mnemonics for the HTTPS status codes provided maybe
by Werkzeug and I missed them?

Thank you. Cheers,
-- 
Daniele

Re: [flask] Simple proposal regard HTTP status codes

From:
Armin Ronacher
Date:
2011-07-26 @ 20:51
Hi,

On 7/26/11 10:36 PM, Daniele Nicolodi wrote:
> I always find myself wondering which is the correct numeric HTTP status
> code I should use with the Flask abort() function. Would it make sense
> to have a few constants defined somewhere in the Flask namespace, like
The reverse is in werkzeug:

  from werkzeug.http import HTTP_STATUS_CODES

They are core -> name.  You could easily reverse them:

  status = dict((v, k) for k, v in HTTP_STATUS_CODES)

Flask itself would never get that mapping, but we could introduce a
reverse mapping into Werkzeug itself if it's useful.


Regards,
Armin

Re: [flask] Simple proposal regard HTTP status codes

From:
Daniele Nicolodi
Date:
2011-07-26 @ 21:05
On 26/07/11 22:51, Armin Ronacher wrote:
>> I always find myself wondering which is the correct numeric HTTP status
>> code I should use with the Flask abort() function. Would it make sense
>> to have a few constants defined somewhere in the Flask namespace, like
> The reverse is in werkzeug:
> 
>   from werkzeug.http import HTTP_STATUS_CODES
> 
> They are core -> name.  You could easily reverse them:
> 
>   status = dict((v, k) for k, v in HTTP_STATUS_CODES)

Isn't that spelled:

   status = dict((v, k) for k, v in HTTP_STATUS_CODES.iteritems())

? :-)

> Flask itself would never get that mapping,

May I ask why?

> but we could introduce a
> reverse mapping into Werkzeug itself if it's useful.

Well, it is an utility for people like me who do not speak HTTP
fluently, but I do not see enough added value to have it added to
Werkzeug, actually. It is very easy to define the few used ones in my
application namespace probably.

Thank you. Cheers,
-- 
Daniele

Re: [flask] Simple proposal regard HTTP status codes

From:
Armin Ronacher
Date:
2011-07-26 @ 20:52
Hi,

On 7/26/11 10:51 PM, Armin Ronacher wrote:
> They are core -> name.  You could easily reverse them:
> 
>   status = dict((v, k) for k, v in HTTP_STATUS_CODES)
Better might be this:


status = dict((v.upper().replace(' ', '_'), k)
              for k, v in HTTP_STATUS_CODES)


Regards,
Armin

Re: [flask] Simple proposal regard HTTP status codes

From:
Kenneth Reitz
Date:
2011-07-26 @ 20:41
 Absolutely. I'm working on a super simple flask extension called 
flask-rest that will have a number of utilities like this. It'll provide a
handful of things (authentication methods, throttling, etc).

It will have something like this inside: 
https://bitbucket.org/jespern/django-piston/src/c4b2d21db51a/piston/utils.py#cl-28


-- 
Kenneth Reitz


On Tuesday, July 26, 2011 at 4:36 PM, Daniele Nicolodi wrote:

> Hello,
> 
> I always find myself wondering which is the correct numeric HTTP status
> code I should use with the Flask abort() function. Would it make sense
> to have a few constants defined somewhere in the Flask namespace, like
> 
> NOT_AUTHORIZED = 403
> NOT_FOUND = 404
> ...
> 
> and so on? Are those mnemonics for the HTTPS status codes provided maybe
> by Werkzeug and I missed them?
> 
> Thank you. Cheers,
> -- 
> Daniele

Re: [flask] Simple proposal regard HTTP status codes

From:
Thomas Schranz
Date:
2011-07-27 @ 07:08
wow, we need this :)

Sent from my iPhone

On Jul 26, 2011, at 22:44, Kenneth Reitz <me@kennethreitz.com> wrote:

 Absolutely. I'm working on a super simple flask extension called flask-rest
that will have a number of utilities like this. It'll provide a handful of
things (authentication methods, throttling, etc).

It will have something like this inside:
https://bitbucket.org/jespern/django-piston/src/c4b2d21db51a/piston/utils.py#cl-28

-- 
Kenneth Reitz

On Tuesday, July 26, 2011 at 4:36 PM, Daniele Nicolodi wrote:

Hello,

I always find myself wondering which is the correct numeric HTTP status
code I should use with the Flask abort() function. Would it make sense
to have a few constants defined somewhere in the Flask namespace, like

NOT_AUTHORIZED = 403
NOT_FOUND = 404
...

and so on? Are those mnemonics for the HTTPS status codes provided maybe
by Werkzeug and I missed them?

Thank you. Cheers,
-- 
Daniele

Re: [flask] Simple proposal regard HTTP status codes

From:
Adam Patterson
Date:
2011-07-26 @ 20:41
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

On Tue, Jul 26, 2011 at 3:36 PM, Daniele Nicolodi <daniele@grinta.net> wrote:
> Hello,
>
> I always find myself wondering which is the correct numeric HTTP status
> code I should use with the Flask abort() function. Would it make sense
> to have a few constants defined somewhere in the Flask namespace, like
>
> NOT_AUTHORIZED = 403
> NOT_FOUND = 404
> ...
>
> and so on? Are those mnemonics for the HTTPS status codes provided maybe
> by Werkzeug and I missed them?
>
> Thank you. Cheers,
> --
> Daniele
>

Re: [flask] Simple proposal regard HTTP status codes

From:
Daniele Nicolodi
Date:
2011-07-26 @ 20:48
On 26/07/11 22:41, Adam Patterson wrote:
> http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

I do not see how this Wikipedia article may help in using intelligible
constant names instead of numeric literals in my code.

Cheers,
-- 
Daniele

Re: [flask] Simple proposal regard HTTP status codes

From:
Adam Patterson
Date:
2011-07-26 @ 20:57
On Tue, Jul 26, 2011 at 3:48 PM, Daniele Nicolodi <daniele@grinta.net> wrote:
> On 26/07/11 22:41, Adam Patterson wrote:
>> http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
>
> I do not see how this Wikipedia article may help in using intelligible
> constant names instead of numeric literals in my code.
>

Sorry, I read the rest of your question and didnt have an answer so I
responded to the first part.

> I always find myself wondering which is the correct numeric HTTP status 
code I should use with the Flask abort() function.

Re: [flask] Simple proposal regard HTTP status codes

From:
Kenneth Reitz
Date:
2011-07-26 @ 21:05
You can track development here: 

https://github.com/kennethreitz/flask-rest 

-- 
Kenneth Reitz


On Tuesday, July 26, 2011 at 4:57 PM, Adam Patterson wrote:

> On Tue, Jul 26, 2011 at 3:48 PM, Daniele Nicolodi <daniele@grinta.net 
(mailto:daniele@grinta.net)> wrote:
> > On 26/07/11 22:41, Adam Patterson wrote:
> > > http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
> > 
> > I do not see how this Wikipedia article may help in using intelligible
> > constant names instead of numeric literals in my code.
> 
> Sorry, I read the rest of your question and didnt have an answer so I
> responded to the first part.
> 
> > I always find myself wondering which is the correct numeric HTTP 
status code I should use with the Flask abort() function.

Re: [flask] Simple proposal regard HTTP status codes

From:
Adam Oakman
Date:
2011-07-26 @ 20:41
It may not be appropriate, but I use the Werkzeug exceptions to handle  
these instances by raising the appropriate exception: NotFound,  
BadRequest, Forbidden etc

http://werkzeug.pocoo.org/docs/exceptions/

On Jul 26, 2011, at 3:36 PM, Daniele Nicolodi wrote:

> Hello,
>
> I always find myself wondering which is the correct numeric HTTP  
> status
> code I should use with the Flask abort() function. Would it make sense
> to have a few constants defined somewhere in the Flask namespace, like
>
> NOT_AUTHORIZED = 403
> NOT_FOUND = 404
> ...
>
> and so on? Are those mnemonics for the HTTPS status codes provided  
> maybe
> by Werkzeug and I missed them?
>
> Thank you. Cheers,
> -- 
> Daniele