X-Git-Url: https://git.auf.org/?p=restcoda.git;a=blobdiff_plain;f=rest.py;h=7e0edc086282b980e35c65c1eca0863b725323c8;hp=cabebfc862fd93efd2d61081ac9c9dbb1a6336c4;hb=0897170cf782f1185693bda8874351ffee8ceef5;hpb=924e2f0a892c3f5d044989917377e5409bde028b diff --git a/rest.py b/rest.py index cabebfc..7e0edc0 100644 --- a/rest.py +++ b/rest.py @@ -18,9 +18,14 @@ from objet import ObjetInconnu # TODO : ajouter un middleware de cache (beaker, basé sur REQUEST_URI quand la methode est GET) # from beaker.middleware import CacheMiddleware -# formats de sortie autorisés, et content-type correspondant -formats = { 'xml': 'application/xml', 'html': 'text/html', 'txt': 'text/plain', 'json': 'application/json', 'rss': 'application/rss+xml', 'debug': 'text/plain' } - +# content-type correspondant a certains formats +contenttype = { 'xml': 'application/xml', + 'rss': 'application/rss+xml', + 'html': 'text/html', + 'txt': 'text/plain', + 'json': 'application/json', + 'csv': 'text/csv', + 'debug': 'text/plain' } # les routes RESTful (cf http://routes.groovie.org/manual.html#restful-services) mapper = Mapper() @@ -60,7 +65,7 @@ def dispatcher(environ, start_response): try: # On lance la méthode et on renvoie le résultat type, output = method(target_class(environ)) - start_response("200 OK", [('Content-type', formats[type] + "; charset=utf-8")]) + start_response("200 OK", [('Content-type', contenttype.get(type,'text/plain') + "; charset=utf-8")]) return output.encode('utf-8') # gestion des problèmes possibles pendant l'exécution except ObjetInconnu, type: