This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""An example of writing an API to scrape hacker news once, and then enabling usage everywhere""" | |
import hug | |
import requests | |
@hug.local() | |
@hug.cli() | |
@hug.get() | |
def top_post(section: hug.types.one_of(('news', 'newest', 'show'))='news'): | |
"""Returns the top post from the provided section""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"404": "The API call you tried to make was not defined. Here's a definition of the API to help you get going :)", | |
"documentation": { | |
"overview": "A basic (single function) API written using Hug", | |
"handlers": { | |
"/happy_birthday": { | |
"GET": { | |
"usage": "Says happy birthday to a user", | |
"examples": [ | |
"http://localhost:8000/happy_birthday?name=HUG&age=1" | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A simple example of a hug API call with versioning""" | |
import hug | |
@hug.get('/echo', versions=1) | |
def echo(text): | |
return text | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''Quite possibly the most simplistic remotely available todo list ever created''' | |
import hot_redis as redis | |
import hug | |
import requests | |
todos = redis.List(key='my_todos') | |
authentication = hug.authentication.basic(hug.authentication.verify(*AUTH)) | |
@hug.get('/todos') | |
def get_todos(): |
NewerOlder