endpoints


Nameendpoints JSON
Version 6.0.0 PyPI version JSON
download
home_page
SummaryGet an api up and running quickly
upload_time2023-09-15 22:46:23
maintainer
docs_urlNone
author
requires_python>=3.10
licenseThe MIT License (MIT) Copyright (c) 2013-2016 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"


### Set Up Your Controller File

Create a controller file with the following command:

    $ touch controllers.py

Add the following code to your new Controller file. These classes are examples of possible *endpoints*.

```python
from endpoints import Controller

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

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

class Foo(Controller):
  async def GET(self):
    return "bang"
```


### 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) 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
    "boom"
    $ curl http://localhost:8000/foo
    "bang"
    $ curl http://localhost:8000/ -d "name=Awesome you"
    "hello Awesome you"

That's it. Easy peasy!

Can you figure out what path endpoints was following in each request?

We see in the ***first request*** that the Controller module was accessed, then the Default class, and then the GET method.

In the ***second request***, the Controller module was accessed, then the Foo class as specified, and then the GET method.

Finally, in the ***last request***, the Controller 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 base 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 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 class is found the class named `Default` will be used.

This makes it easy to bundle your controllers into something like a "Controllers" 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) |

As shown above, we see that **endpoints essentially travels the path from the base module down to the appropriate submodule according to the request given.**


### 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()     |

If you have gotten to this point, congratulations. You understand the basics of endpoints. If you don't understand endpoints then please go back and read from the top again before reading any further.


## Learn more about Endpoints

Now you should dive into some of the other features discussed in the [docs folder](https://github.com/jaymon/endpoints/tree/master/docs).


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "endpoints",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "asgi,asgi-server,wsgi,wsgi-server,api,api-server,server,framework,web-framework,REST,rest-api",
    "author": "",
    "author_email": "Jay Marcyes <jay@marcyes.com>",
    "download_url": "https://files.pythonhosted.org/packages/19/8b/4e31bc7a249d4b90070c4c3555c69a1e8e7090be6c9ac95bedf507d9ab0d/endpoints-6.0.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### Set Up Your Controller File\n\nCreate a controller file with the following command:\n\n    $ touch controllers.py\n\nAdd the following code to your new Controller file. These classes are examples of possible *endpoints*.\n\n```python\nfrom endpoints import Controller\n\nclass Default(Controller):\n  async def GET(self):\n    return \"boom\"\n\n  async def POST(self, **kwargs):\n    return 'hello {}'.format(kwargs['name'])\n\nclass Foo(Controller):\n  async def GET(self):\n    return \"bang\"\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) and 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    \"boom\"\n    $ curl http://localhost:8000/foo\n    \"bang\"\n    $ curl http://localhost:8000/ -d \"name=Awesome you\"\n    \"hello Awesome you\"\n\nThat's it. Easy peasy!\n\nCan you figure out what path endpoints was following in each request?\n\nWe see in the ***first request*** that the Controller module was accessed, then the Default class, and then the GET method.\n\nIn the ***second request***, the Controller module was accessed, then the Foo class as specified, and then the GET method.\n\nFinally, in the ***last request***, the Controller 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 base 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 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 class is found the class named `Default` will be used.\n\nThis makes it easy to bundle your controllers into something like a \"Controllers\" 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\nAs shown above, we see that **endpoints essentially travels the path from the base module down to the appropriate submodule according to the request given.**\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\nIf you have gotten to this point, congratulations. You understand the basics of endpoints. If you don't understand endpoints then please go back and read from the top again before reading any further.\n\n\n## Learn more about Endpoints\n\nNow you should dive into some of the other features discussed in the [docs folder](https://github.com/jaymon/endpoints/tree/master/docs).\n\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2013-2016 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": "6.0.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": "ed7e933fef8581b25a73cfa8cbf621c29a7d3f10f75b0593906d053b28ccf929",
                "md5": "ae9bfce5e42226351d46b935aca7bca7",
                "sha256": "65a6c440b39601cbcf74e4fd4a5c4cf5262e9602e3473a4b06be19f0dcd1fdf6"
            },
            "downloads": -1,
            "filename": "endpoints-6.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ae9bfce5e42226351d46b935aca7bca7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 52078,
            "upload_time": "2023-09-15T22:46:21",
            "upload_time_iso_8601": "2023-09-15T22:46:21.087400Z",
            "url": "https://files.pythonhosted.org/packages/ed/7e/933fef8581b25a73cfa8cbf621c29a7d3f10f75b0593906d053b28ccf929/endpoints-6.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "198b4e31bc7a249d4b90070c4c3555c69a1e8e7090be6c9ac95bedf507d9ab0d",
                "md5": "0c863a404094a3085992d70d197e6362",
                "sha256": "6d8cb4ce7ef8a96b9ab272cd0ab144cc13dff0d7e5abd4538104ba8f242f2507"
            },
            "downloads": -1,
            "filename": "endpoints-6.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0c863a404094a3085992d70d197e6362",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 46775,
            "upload_time": "2023-09-15T22:46:23",
            "upload_time_iso_8601": "2023-09-15T22:46:23.314492Z",
            "url": "https://files.pythonhosted.org/packages/19/8b/4e31bc7a249d4b90070c4c3555c69a1e8e7090be6c9ac95bedf507d9ab0d/endpoints-6.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-15 22:46:23",
    "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: 0.12085s