Skip to content

Instantly share code, notes, and snippets.

View timothycrosley's full-sized avatar
🤔
Next experiment incoming

Timothy Edmund Crosley timothycrosley

🤔
Next experiment incoming
View GitHub Profile
@timothycrosley
timothycrosley / write_once.py
Last active March 31, 2021 20:37
Write once run every where
"""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"""
@timothycrosley
timothycrosley / documentation.json
Created March 11, 2016 07:05
Auto generated documentation
{"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"
],
@timothycrosley
timothycrosley / versioning.py
Created March 11, 2016 07:00
A simple example of a hug API call with versioning
"""A simple example of a hug API call with versioning"""
import hug
@hug.get('/echo', versions=1)
def echo(text):
return text
@timothycrosley
timothycrosley / simple_todo.py
Created September 9, 2015 22:59
Simple todo for puppy meetup
'''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():