def run(host="localhost", user="******", password="******", database="opendkim", bindAddress='', bindPort=8000): "This program runs a web server to retrieve reputation data from the opendkim database" outputRegistry = OutputRegistry('application/reputon+json') outputRegistry.register('application/reputon+json', jsonDateFormatter) outputRegistry.register('text/html', jsonDateFormatter) api = SaratogaAPI(DKIM, DKIM_APIDef, serviceClass=Database(user=user, password=password, host=host, database=database), outputRegistry=outputRegistry) api.run(port=bindPort)
import json from saratoga.api import SaratogaAPI class PlanetAPI(object): class v1(object): def yearlength_GET(self, request, params): planetName = params["params"]["name"].lower() if planetName == "earth": return {"seconds": 31536000} elif planetName == "pluto": return {"seconds": 7816176000} APIDescription = json.load(open("planets.json")) myAPI = SaratogaAPI(PlanetAPI, APIDescription) myAPI.run(port=8094)
from saratoga.api import SaratogaAPI import json class ServiceClassExample(object): stuff = "foo" class ExampleAPI(object): class v1(object): def example_GET(self, request, params): return self.stuff api = SaratogaAPI(ExampleAPI, json.load(open("simple.json")), serviceClass=ServiceClassExample()) api.run()