Skip to content

Instantly share code, notes, and snippets.

@greut
Last active May 18, 2017 14:49
Show Gist options
  • Save greut/62432a60975a00b92fc23ec654c80279 to your computer and use it in GitHub Desktop.
Save greut/62432a60975a00b92fc23ec654c80279 to your computer and use it in GitHub Desktop.
API REST avec Hug
$ hug -f light.py
/#######################################################################\
`.----``..-------..``.----.
:/:::::--:---------:--::::://.
.+::::----##/-/oo+:-##----:::://
`//::-------/oosoo-------::://. ## ## ## ## #####
.-:------./++o/o-.------::-` ``` ## ## ## ## ##
`----.-./+o+:..----. `.:///. ######## ## ## ##
``` `----.-::::::------ `.-:::://. ## ## ## ## ## ####
://::--.``` -:``...-----...` `:--::::::-.` ## ## ## ## ## ##
:/:::::::::-:- ````` .:::::-.` ## ## #### ######
``.--:::::::. .:::.`
``..::. .:: EMBRACE THE APIs OF THE FUTURE
::- .:-
-::` ::- VERSION 2.3.0
`::- -::`
-::-` -::-
\########################################################################/
Copyright (C) 2016 Timothy Edmund Crosley
Under the MIT License
Serving on port 8000...
127.0.0.1 - - [18/May/2017 12:42:58] "GET /light HTTP/1.1" 200 5
127.0.0.1 - - [18/May/2017 12:43:03] "POST /light HTTP/1.1" 200 4
127.0.0.1 - - [18/May/2017 12:43:05] "GET /light HTTP/1.1" 200 4
# dans un autre terminal.
$ curl http://localhost:8000/light
false
$ curl -d state=true http://localhost:8000/light
true
$ curl http://localhost:8000/light
true
$ curl -d state= http://localhost:8000/light
false
$ curl http://localhost:8000/light
false
import hug
light = False
@hug.get('/light')
def get_light():
return light
@hug.post('/light')
def set_light(state:bool=False):
global light
light = state
return light
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment