Skip to content

Commit c4c7d67

Browse files
Merge pull request #806 from EdvardM/issue/805
Issue/805
2 parents 7929150 + cfa0198 commit c4c7d67

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,6 @@ venv/
7373

7474
# Emacs backup
7575
*~
76+
77+
# VSCode
78+
/.vscode

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ As a result of these goals, hug is Python 3+ only and built upon [Falcon's](http
2525

2626
[![HUG Hello World Example](https://raw.github.com/hugapi/hug/develop/artwork/example.gif)](https://github.com/hugapi/hug/blob/develop/examples/hello_world.py)
2727

28-
2928
Installing hug
3029
===================
3130

@@ -37,9 +36,9 @@ pip3 install hug --upgrade
3736

3837
Ideally, within a [virtual environment](http://docs.python-guide.org/en/latest/dev/virtualenvs/).
3938

40-
4139
Getting Started
4240
===================
41+
4342
Build an example API with a simple endpoint in just a few lines.
4443

4544
```py
@@ -118,7 +117,6 @@ Then you can access the example from `localhost:8000/v1/echo?text=Hi` / `localho
118117

119118
Note: versioning in hug automatically supports both the version header as well as direct URL based specification.
120119

121-
122120
Testing hug APIs
123121
===================
124122

@@ -141,7 +139,6 @@ def tests_happy_birthday():
141139
assert response.data is not None
142140
```
143141

144-
145142
Running hug with other WSGI based servers
146143
===================
147144

@@ -155,7 +152,6 @@ uwsgi --http 0.0.0.0:8000 --wsgi-file examples/hello_world.py --callable __hug_w
155152

156153
To run the hello world hug example API.
157154

158-
159155
Building Blocks of a hug API
160156
===================
161157

@@ -182,7 +178,6 @@ def math(number_1:int, number_2:int): #The :int after both arguments is the Type
182178
Type annotations also feed into `hug`'s automatic documentation
183179
generation to let users of your API know what data to supply.
184180

185-
186181
**Directives** functions that get executed with the request / response data based on being requested as an argument in your api_function.
187182
These apply as input parameters only, and can not be applied currently as output formats or transformations.
188183

@@ -242,7 +237,6 @@ def hello():
242237

243238
as shown, you can easily change the output format for both an entire API as well as an individual API call
244239

245-
246240
**Input Formatters** a function that takes the body of data given from a user of your API and formats it for handling.
247241

248242
```py
@@ -253,7 +247,6 @@ def my_input_formatter(data):
253247

254248
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`
255249

256-
257250
**Middleware** functions that get called for every request a hug API processes
258251

259252
```py
@@ -272,6 +265,18 @@ You can also easily add any Falcon style middleware using:
272265
__hug__.http.add_middleware(MiddlewareObject())
273266
```
274267

268+
**Parameter mapping** can be used to override inferred parameter names, eg. for reserved keywords:
269+
270+
```py
271+
import marshmallow.fields as fields
272+
...
273+
274+
@hug.get('/foo', map_params={'from': 'from_date'}) # API call uses 'from'
275+
def get_foo_by_date(from_date: fields.DateTime()):
276+
return find_foo(from_date)
277+
```
278+
279+
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`
275280

276281
Splitting APIs over multiple files
277282
===================
@@ -314,7 +319,6 @@ Or alternatively - for cases like this - where only one module is being included
314319
hug.API(__name__).extend(something, '/something')
315320
```
316321

317-
318322
Configuring hug 404
319323
===================
320324

@@ -346,14 +350,14 @@ def not_found_handler():
346350
return "Not Found"
347351
```
348352

349-
350353
Asyncio support
351354
===============
352355

353356
When using the `get` and `cli` method decorator on coroutines, hug will schedule
354357
the execution of the coroutine.
355358

356359
Using asyncio coroutine decorator
360+
357361
```py
358362
@hug.get()
359363
@asyncio.coroutine
@@ -362,6 +366,7 @@ def hello_world():
362366
```
363367

364368
Using Python 3.5 async keyword.
369+
365370
```py
366371
@hug.get()
367372
async def hello_world():
@@ -371,9 +376,9 @@ async def hello_world():
371376
NOTE: Hug is running on top Falcon which is not an asynchronous server. Even if using
372377
asyncio, requests will still be processed synchronously.
373378

374-
375379
Using Docker
376380
===================
381+
377382
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/).
378383

379384
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.
@@ -413,7 +418,6 @@ bash-4.3# tree
413418
1 directory, 3 files
414419
```
415420

416-
417421
Why hug?
418422
===================
419423

0 commit comments

Comments
 (0)