In [10]:
import hug
import webcolors
In [11]:
@hug.get()
def hextoname(hex: hug.types.text):
return webcolors.hex_to_name('#' + hex)
In [12]:
@hug.get()
def nametohex(name: hug.types.text):
return webcolors.name_to_hex(name)
hug started from the command line in another terminal
hug -f embrace_hug.py -p 3000
In [13]:
!curl http://localhost:3000
# expect to get help because an undefined call was made
In [14]:
!curl http://localhost:3000/nametohex
# expect to get error because name not supplied
In [15]:
!curl http://localhost:3000/nametohex/?name=red
# expect to get a hex color for red
In [16]:
!curl http://localhost:3000/nametohex/?name=limegreen
# expect to get a hex color for limegreen
In [17]:
!curl http://localhost:3000/hextoname/?hex=32cd32
# expect to get a word for the color
In [19]:
!jupyter nbconvert --to pdf embrace_hug.ipynb