{"id":17796384,"url":"https://github.com/d-plaindoux/fluent-rest","last_synced_at":"2025-04-02T03:20:19.976Z","repository":{"id":15360019,"uuid":"18090964","full_name":"d-plaindoux/fluent-rest","owner":"d-plaindoux","description":"Fluent REST decorators (annotations) dedicated to Web framework","archived":false,"fork":false,"pushed_at":"2016-11-04T13:17:33.000Z","size":106,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-07T17:50:25.060Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"jaimurugan/CardViewSample","license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/d-plaindoux.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-25T06:30:39.000Z","updated_at":"2016-03-23T05:53:28.000Z","dependencies_parsed_at":"2022-09-01T00:50:55.649Z","dependency_job_id":null,"html_url":"https://github.com/d-plaindoux/fluent-rest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-plaindoux%2Ffluent-rest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-plaindoux%2Ffluent-rest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-plaindoux%2Ffluent-rest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-plaindoux%2Ffluent-rest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d-plaindoux","download_url":"https://codeload.github.com/d-plaindoux/fluent-rest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246747496,"owners_count":20827163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-27T11:45:16.253Z","updated_at":"2025-04-02T03:20:19.947Z","avatar_url":"https://github.com/d-plaindoux.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fluent-rest\n\n[![Build Status](https://travis-ci.org/d-plaindoux/fluent-rest.svg?branch=master)](https://travis-ci.org/d-plaindoux/fluent-rest)\n[![Coverage Status](https://coveralls.io/repos/d-plaindoux/fluent-rest/badge.svg?branch=master)](https://coveralls.io/r/d-plaindoux/fluent-rest?branch=master)\n[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)\n\n# Introduction\n\nThis library provides REST specification facilities dedicated to\npython web frameworks.\n\n# `Todo` Example\n\nIn this example we show how decorators can be used in order to specify a REST\nservice dedicated to `Todo` data.\n\n```python\nfrom fluent_rest.rest import *\nfrom fluent_rest.response import WebException\n\n\nclass TodoNotFound(Exception):\n    def __init__(self, id):\n        self.id = id\n\ndef UUIDToString(uuid):\n    return str(uuid)\n\n\ndef TodoToJson(dictionary):\n    result = {}\n    for key in dictionary.keys():\n        result[str(key)] = dictionary[key]\n    return dumps(result)\n\n@Path(\"/todo\")\n@Consumes(\"application/json\")\n@Produces(\"application/json\")\nclass TodoApp:\n    def __init__(self):\n        self.__todo = {}\n\n    @GET\n    @Produces(\"application/json\", TodoToJson)\n    def list(self):\n        return self.__todo\n\n    @GET\n    @Path(\"{id:uuid}\")\n    @Produces(\"application/json\", UUIDToString)\n    def get(self, id):\n        if id in self.__todo:\n            return self.__todo[id]\n        else:\n            raise TodoNotFound(id)\n\n    @POST\n    @Produces(\"application/json\", UUIDToString)\n    def create(self, data):\n        id = uuid.uuid1()\n        self.__todo[id] = data\n        return id\n\n    @PUT\n    @Path(\"{id:uuid}\")\n    @Produces(\"application/json\", UUIDToString)\n    def modify(self, id, data):\n        if id in self.__todo:\n            self.__todo[id] = data\n            return id\n        else:\n            raise TodoNotFound(id)\n\n    @DELETE\n    @Path(\"{id:uuid}\")\n    @Produces(\"application/json\", UUIDToString)\n    def remove(self, id):\n        if id in self.__todo:\n            del self.__todo[id]\n            return id\n        else:\n            raise TodoNotFound(id)\n\n    @Provider(TodoNotFound)\n    def notFound(e):\n        raise WebException.notFound(\"todo %s not found\" % e.id)\n```\n\nThen creating a WSGI server instance based on utility library like\n[Werkzeug](http://werkzeug.pocoo.org) can be easily done using provided\nbridge.\n\n```python\nfrom werkzeug import serving\nfrom werkzeug import wrappers\nfrom fluent_rest.bridge.werkzeugbridge import WerkzeugBridge\n\nbridge = WerkzeugBridge(). \\\n    register(TodoApp()).   \\\n    bind(lambda a: serving.run_simple('localhost',\n                                      4000,\n                                      wrappers.Request.application(a))\n)\n```\n\n# Decorators\n\nThe fluent-rest library provides a set of decorators applied at the\nclass or at the method level. Decorators at the class level define\nspecification which are general like the path and available encoders and\ndecoders. At the method level verbs are required and additional path can\nalso be specified completing the class level path.\n\n## `@Path(path)`\n\nA path decorator defines the path associated to a given REST service. A path\ncorresponds to an URI to which a resource respond. Such path can be a simple\n URI or a template URI. A template URI defines typed variables bound\nat the runtime.\n\n### Syntax\n\n```\npath = '/'? item ('/' item)* '/'?\n\nitem = '{' IDENT (':' type) '}'\n     | (CHAR - {'/','{'})+\n\ntype = 'int' | 'float' | 'string' | 'path' | 'uuid'\n```\n\n### Examples\n\nThe path specficiation `/foo/{bar:string}/baz` matches path like\n`/foo/a-string/baz` binding  `bar` variable to `a-string` ; match does not\nsucceed for path like  `/foo/a/string/baz` because `a/string` is a sub path.\n For this purpose the path type has been proposed and can be used to bind a\n sub path. Then the path specification `/foo/{bar:path}/baz` matches\n `/foo/a/string/baz` binding `bar` to `a/string` sub path.\n\n### Extending path types\n\nTODO\n\n## `@Consumes(mime,...)` and `@Produces(mime,...)`\n\nEach request comes with its constraints related to input and output\nrepresentation. This is commonly denoted using mime and each of it has it\nown transformation process. A second parameter can be added specifying the\ntransformation process to be applied when the result is send back to the\nclient.\n\n## `@GET` `@POST` `@PUT` `@DELETE` and `@Verb(verb)`\n\nIn the REST approach a method - or verb - is fundamental.  The primary HTTP\nverbs are POST, GET, PUT, and DELETE. These correspond respectively to\ncreate, read, update, and delete operations aka CRUD model. There are a\nnumber of other verbs, too, but less frequently used. For this last\ncategory of verbs the specification is done using `@Verb(...)` decorator.\n\n## `@Provider(Class)`\n\nA provider can be used in different situations like:\n- exception mapping transforming an exception to a `WebException`\n- result mapping transforming a data to another one for serialization purpose.\n\n# License\n\nCopyright (C)2015 D. Plaindoux.\n\nThis program is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as published\nby the Free Software Foundation; either version 2, or (at your option)\nany later version.\n\nThis program is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\nor FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License\nfor more details.\n\nYou should have received a copy of the GNU Lesser General Public License\nalong with this program; see the file COPYING. If not, write to the Free\nSoftware Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd-plaindoux%2Ffluent-rest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd-plaindoux%2Ffluent-rest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd-plaindoux%2Ffluent-rest/lists"}