You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+4-12Lines changed: 4 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,6 @@ As a result of these goals, hug is Python 3+ only and built upon [Falcon's](http
25
25
26
26
[](https://github.com/hugapi/hug/blob/develop/examples/hello_world.py)
27
27
28
-
29
28
Installing hug
30
29
===================
31
30
@@ -37,9 +36,9 @@ pip3 install hug --upgrade
37
36
38
37
Ideally, within a [virtual environment](http://docs.python-guide.org/en/latest/dev/virtualenvs/).
39
38
40
-
41
39
Getting Started
42
40
===================
41
+
43
42
Build an example API with a simple endpoint in just a few lines.
44
43
45
44
```py
@@ -118,7 +117,6 @@ Then you can access the example from `localhost:8000/v1/echo?text=Hi` / `localho
118
117
119
118
Note: versioning in hug automatically supports both the version header as well as direct URL based specification.
@@ -182,7 +178,6 @@ def math(number_1:int, number_2:int): #The :int after both arguments is the Type
182
178
Type annotations also feed into `hug`'s automatic documentation
183
179
generation to let users of your API know what data to supply.
184
180
185
-
186
181
**Directives** functions that get executed with the request / response data based on being requested as an argument in your api_function.
187
182
These apply as input parameters only, and can not be applied currently as output formats or transformations.
188
183
@@ -242,7 +237,6 @@ def hello():
242
237
243
238
as shown, you can easily change the output format for both an entire API as well as an individual API call
244
239
245
-
246
240
**Input Formatters** a function that takes the body of data given from a user of your API and formats it for handling.
247
241
248
242
```py
@@ -253,7 +247,6 @@ def my_input_formatter(data):
253
247
254
248
Input formatters are mapped based on the `content_type` of the request data, and only perform basic parsing. More detailed parsing should be done by the Type Annotations present on your `api_function`
255
249
256
-
257
250
**Middleware** functions that get called for every request a hug API processes
258
251
259
252
```py
@@ -314,7 +307,6 @@ Or alternatively - for cases like this - where only one module is being included
314
307
hug.API(__name__).extend(something, '/something')
315
308
```
316
309
317
-
318
310
Configuring hug 404
319
311
===================
320
312
@@ -346,14 +338,14 @@ def not_found_handler():
346
338
return"Not Found"
347
339
```
348
340
349
-
350
341
Asyncio support
351
342
===============
352
343
353
344
When using the `get` and `cli` method decorator on coroutines, hug will schedule
354
345
the execution of the coroutine.
355
346
356
347
Using asyncio coroutine decorator
348
+
357
349
```py
358
350
@hug.get()
359
351
@asyncio.coroutine
@@ -362,6 +354,7 @@ def hello_world():
362
354
```
363
355
364
356
Using Python 3.5 async keyword.
357
+
365
358
```py
366
359
@hug.get()
367
360
asyncdefhello_world():
@@ -371,9 +364,9 @@ async def hello_world():
371
364
NOTE: Hug is running on top Falcon which is not an asynchronous server. Even if using
372
365
asyncio, requests will still be processed synchronously.
373
366
374
-
375
367
Using Docker
376
368
===================
369
+
377
370
If you like to develop in Docker and keep your system clean, you can do that but you'll need to first install [Docker Compose](https://docs.docker.com/compose/install/).
378
371
379
372
Once you've done that, you'll need to `cd` into the `docker` directory and run the web server (Gunicorn) specified in `./docker/gunicorn/Dockerfile`, after which you can preview the output of your API in the browser on your host machine.
0 commit comments