Skip to content

Commit

Permalink
README edits
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaymon committed Dec 8, 2024
1 parent 0fed4f0 commit 70cd516
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 48 deletions.
54 changes: 6 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# 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
## Getting Started

### Installation

Expand All @@ -24,7 +22,7 @@ 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).
Add the following code to the `controllers.py` file:

```python
from endpoints import Controller
Expand Down Expand Up @@ -59,7 +57,8 @@ Install [Daphne](https://github.com/django/daphne):

And start it:

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


### Test it out

Expand All @@ -72,13 +71,13 @@ Using curl:
$ curl http://localhost:8000/ -d "name=Awesome you"
"hello Awesome you"

That's it. Easy peasy!
That's it!

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.
Finally, in the ***last request***, the `controllers` module was accessed, then the `Default` class, and finally the `POST` method with the passed in argument.


## How does it work?
Expand All @@ -98,47 +97,6 @@ Once the module is found, endpoints will then attempt to find the class with the

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

Expand Down
51 changes: 51 additions & 0 deletions docs/CONTROLLERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,54 @@ class Default(Controller):
```

Endpoints first checks module paths, then it checks classes in the found module, then defaults to the `Default` class if no other suitable class is found.


## Another Example

Imagine a folder structure like this:

```
controllers/
__init__.py
foo.py
```

With `controllers/__init__.py` having content:

```python
from endpoints import Controller

class Default(Controller):
async def GET(self, *args, **kwargs):
pass
```

And `controllers/foo.py` having content:

```python
from endpoints import Controller

class Default(Controller):
async def GET(self, *args, **kwargs):
pass

class Bar(Controller):
async def GET(self, *args, **kwargs):
pass

async def POST(self, *args, **kwargs):
pass
```


Below are how the HTTP requests would be interpreted using endpoints using `controllers` as the prefix.


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

0 comments on commit 70cd516

Please sign in to comment.