endpoints


Nameendpoints JSON
Version 7.1.0 PyPI version JSON
download
home_pageNone
SummaryGet an api up and running quickly
upload_time2024-11-22 22:02:09
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseThe MIT License (MIT) Copyright (c) 2013+ Jay Marcyes Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords asgi asgi-server wsgi wsgi-server api api-server server framework web-framework rest rest-api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Endpoints

Quickest API builder in the West! 

_Endpoints_ is a lightweight REST api framework written in python that supports both WSGI and ASGI. _Endpoints_ has been used in multiple production systems that handle millions of requests daily.


## 5 Minute Getting Started

### Installation

First, install endpoints with the following command.

    $ pip install endpoints

If you want the latest and greatest you can also install from source:

    $ pip install -U "git+https://github.com/jaymon/endpoints#egg=endpoints"


### Create a Controller Module

Create a controller file with the following command:

    $ touch controllers.py

Add the following code to the `controllers.py` file (These controller classes are just to help you get started and understand how endpoints works).

```python
from endpoints import Controller

class Default(Controller):
  """The special class `Default` handles / requests"""
  async def GET(self):
    return "Default handler"

  async def POST(self, **kwargs):
    return 'hello {}'.format(kwargs['name'])

class Foo(Controller):
  """This class handles `/foo` requests"""
  async def GET(self):
    return "Foo handler"
```


### Start a WSGI Server

Now that you have your `controllers.py`, let's use the built-in WSGI server to serve them, we'll set our `controllers.py` file as the [controller prefix](docs/PREFIXES.md) so Endpoints will know where to find the [Controller classes](docs/CONTROLLERS.md) we just defined:

    $ endpoints --prefix=controllers --host=localhost:8000


### Start an ASGI Server

Install [Daphne](https://github.com/django/daphne):

    $ pip install -U daphne

And start it:

    $ ENDPOINTS_PREFIX=controllers daphne -b localhost -p 8000 -v 3 endpoints.interface.asgi:ApplicationFactory

### Test it out

Using curl:

    $ curl http://localhost:8000
    "Default handler"
    $ curl http://localhost:8000/foo
    "Foo handler"
    $ curl http://localhost:8000/ -d "name=Awesome you"
    "hello Awesome you"

That's it. Easy peasy!

In the ***first request*** (`/`), the `controllers` module was accessed, then the `Default` class, and then the `GET` method.

In the ***second request*** (`/foo`), the `controllers` module was accessed, then the `Foo` class as specified in the path of the url, and then the `GET` method.

Finally, in the ***last request***, the `controllers` module was accessed, then the `Default` class, and finally the `POST` method with the passed in argument as JSON.


## How does it work?

*Endpoints* translates requests to python modules without any configuration.

It uses the following convention.

    METHOD /module/class/args?kwargs

_Endpoints_ will use the prefix module you set as a reference point to find the correct submodule using the path specified by the request.

Requests are translated from the left bit to the right bit of the path.
So for the path `/foo/bar/che/baz`, endpoints would first check for the `foo` module, then the `foo.bar` module, then the `foo.bar.che` module, etc. until it fails to find a valid module.

Once the module is found, endpoints will then attempt to find the class with the remaining path bits. If no matching class is found then a class named `Default` will be used if it exists.

This makes it easy to bundle your controllers into a `controllers` package/module.

Below are some examples of HTTP requests and how they would be interpreted using endpoints.

**Note:** prefix refers to the name of the base module that you set.

|HTTP Request                           | Path Followed                     |
|---------------------------------------|---------------------------------- |
|GET /                                  | prefix.Default.GET()              |
|GET /foo                               | prefix.foo.Default.GET()          |
|POST /foo/bar                          | prefix.foo.Bar.POST()             |
|GET /foo/bar/che                       | prefix.foo.Bar.GET(che)           |
|GET /foo/bar/che?baz=foo               | prefix.foo.Bar.GET(che, baz=foo)  |
|POST /foo/bar/che with body: baz=foo   | prefix.foo.Bar.POST(che, baz=foo) |


### One more example

Let's say your site had the following setup:

    site/controllers/__init__.py

and the file `controllers/__init__.py` contained:

```python
from endpoints import Controller

class Default(Controller):
  async def GET(self):
    return "called /"

class Foo(Controller):
  async def GET(self):
    return "called /foo"
```

then your call requests would be translated like this:

|HTTP Request   | Path Followed             |
|-------------- | ------------------------- |
|GET /          | controllers.Default.GET() |
|GET /foo       | controllers.Foo.GET()     |


## Learn more about Endpoints

The [docs](https://github.com/jaymon/endpoints/tree/master/docs) contain more information about how _Endpoints_ works and what can be done with it.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "endpoints",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "asgi, asgi-server, wsgi, wsgi-server, api, api-server, server, framework, web-framework, REST, rest-api",
    "author": null,
    "author_email": "Jay Marcyes <jay@marcyes.com>",
    "download_url": "https://files.pythonhosted.org/packages/48/b3/b9925b05ac89ab95249ba2b11fd3ebdf8264d053e8e3408875ebb27acd0b/endpoints-7.1.0.tar.gz",
    "platform": null,
    "description": "# Endpoints\n\nQuickest API builder in the West! \n\n_Endpoints_ is a lightweight REST api framework written in python that supports both WSGI and ASGI. _Endpoints_ has been used in multiple production systems that handle millions of requests daily.\n\n\n## 5 Minute Getting Started\n\n### Installation\n\nFirst, install endpoints with the following command.\n\n    $ pip install endpoints\n\nIf you want the latest and greatest you can also install from source:\n\n    $ pip install -U \"git+https://github.com/jaymon/endpoints#egg=endpoints\"\n\n\n### Create a Controller Module\n\nCreate a controller file with the following command:\n\n    $ touch controllers.py\n\nAdd the following code to the `controllers.py` file (These controller classes are just to help you get started and understand how endpoints works).\n\n```python\nfrom endpoints import Controller\n\nclass Default(Controller):\n  \"\"\"The special class `Default` handles / requests\"\"\"\n  async def GET(self):\n    return \"Default handler\"\n\n  async def POST(self, **kwargs):\n    return 'hello {}'.format(kwargs['name'])\n\nclass Foo(Controller):\n  \"\"\"This class handles `/foo` requests\"\"\"\n  async def GET(self):\n    return \"Foo handler\"\n```\n\n\n### Start a WSGI Server\n\nNow that you have your `controllers.py`, let's use the built-in WSGI server to serve them, we'll set our `controllers.py` file as the [controller prefix](docs/PREFIXES.md) so Endpoints will know where to find the [Controller classes](docs/CONTROLLERS.md) we just defined:\n\n    $ endpoints --prefix=controllers --host=localhost:8000\n\n\n### Start an ASGI Server\n\nInstall [Daphne](https://github.com/django/daphne):\n\n    $ pip install -U daphne\n\nAnd start it:\n\n    $ ENDPOINTS_PREFIX=controllers daphne -b localhost -p 8000 -v 3 endpoints.interface.asgi:ApplicationFactory\n\n### Test it out\n\nUsing curl:\n\n    $ curl http://localhost:8000\n    \"Default handler\"\n    $ curl http://localhost:8000/foo\n    \"Foo handler\"\n    $ curl http://localhost:8000/ -d \"name=Awesome you\"\n    \"hello Awesome you\"\n\nThat's it. Easy peasy!\n\nIn the ***first request*** (`/`), the `controllers` module was accessed, then the `Default` class, and then the `GET` method.\n\nIn the ***second request*** (`/foo`), the `controllers` module was accessed, then the `Foo` class as specified in the path of the url, and then the `GET` method.\n\nFinally, in the ***last request***, the `controllers` module was accessed, then the `Default` class, and finally the `POST` method with the passed in argument as JSON.\n\n\n## How does it work?\n\n*Endpoints* translates requests to python modules without any configuration.\n\nIt uses the following convention.\n\n    METHOD /module/class/args?kwargs\n\n_Endpoints_ will use the prefix module you set as a reference point to find the correct submodule using the path specified by the request.\n\nRequests are translated from the left bit to the right bit of the path.\nSo for the path `/foo/bar/che/baz`, endpoints would first check for the `foo` module, then the `foo.bar` module, then the `foo.bar.che` module, etc. until it fails to find a valid module.\n\nOnce the module is found, endpoints will then attempt to find the class with the remaining path bits. If no matching class is found then a class named `Default` will be used if it exists.\n\nThis makes it easy to bundle your controllers into a `controllers` package/module.\n\nBelow are some examples of HTTP requests and how they would be interpreted using endpoints.\n\n**Note:** prefix refers to the name of the base module that you set.\n\n|HTTP Request                           | Path Followed                     |\n|---------------------------------------|---------------------------------- |\n|GET /                                  | prefix.Default.GET()              |\n|GET /foo                               | prefix.foo.Default.GET()          |\n|POST /foo/bar                          | prefix.foo.Bar.POST()             |\n|GET /foo/bar/che                       | prefix.foo.Bar.GET(che)           |\n|GET /foo/bar/che?baz=foo               | prefix.foo.Bar.GET(che, baz=foo)  |\n|POST /foo/bar/che with body: baz=foo   | prefix.foo.Bar.POST(che, baz=foo) |\n\n\n### One more example\n\nLet's say your site had the following setup:\n\n    site/controllers/__init__.py\n\nand the file `controllers/__init__.py` contained:\n\n```python\nfrom endpoints import Controller\n\nclass Default(Controller):\n  async def GET(self):\n    return \"called /\"\n\nclass Foo(Controller):\n  async def GET(self):\n    return \"called /foo\"\n```\n\nthen your call requests would be translated like this:\n\n|HTTP Request   | Path Followed             |\n|-------------- | ------------------------- |\n|GET /          | controllers.Default.GET() |\n|GET /foo       | controllers.Foo.GET()     |\n\n\n## Learn more about Endpoints\n\nThe [docs](https://github.com/jaymon/endpoints/tree/master/docs) contain more information about how _Endpoints_ works and what can be done with it.\n\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2013+ Jay Marcyes  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Get an api up and running quickly",
    "version": "7.1.0",
    "project_urls": {
        "Homepage": "https://github.com/Jaymon/endpoints",
        "Repository": "https://github.com/Jaymon/endpoints"
    },
    "split_keywords": [
        "asgi",
        " asgi-server",
        " wsgi",
        " wsgi-server",
        " api",
        " api-server",
        " server",
        " framework",
        " web-framework",
        " rest",
        " rest-api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bc8d21a80369eee59e1e355b3b7210857324f3b323583c48b0be00ebe9bb1d73",
                "md5": "c4b75be3c8755fcb388319dfd29b1ce1",
                "sha256": "45fa12f3047092acdb5855a9f44fd17435bfa0175df1ebbf99dd686d17b0686d"
            },
            "downloads": -1,
            "filename": "endpoints-7.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c4b75be3c8755fcb388319dfd29b1ce1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 72276,
            "upload_time": "2024-11-22T22:02:11",
            "upload_time_iso_8601": "2024-11-22T22:02:11.978522Z",
            "url": "https://files.pythonhosted.org/packages/bc/8d/21a80369eee59e1e355b3b7210857324f3b323583c48b0be00ebe9bb1d73/endpoints-7.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "48b3b9925b05ac89ab95249ba2b11fd3ebdf8264d053e8e3408875ebb27acd0b",
                "md5": "4054f8dc214361514ea02b9c2895568a",
                "sha256": "9f1146c6bbe01fe0d9ab4333bcbede0d15db1553a86e30f3d8219de17f9e8955"
            },
            "downloads": -1,
            "filename": "endpoints-7.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4054f8dc214361514ea02b9c2895568a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 65554,
            "upload_time": "2024-11-22T22:02:09",
            "upload_time_iso_8601": "2024-11-22T22:02:09.912935Z",
            "url": "https://files.pythonhosted.org/packages/48/b3/b9925b05ac89ab95249ba2b11fd3ebdf8264d053e8e3408875ebb27acd0b/endpoints-7.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-22 22:02:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Jaymon",
    "github_project": "endpoints",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "endpoints"
}
        
Elapsed time: 2.20011s