Пример #1
0
def makeService(options):
    """
    Make a service.

    @param options: The option parameters.
    @return: A service.
    """

    tsAPIService = API(
        tsAPI, json.load(open("tomatosalad/static/json/api.json")),
        serviceClass=tsServiceClass())

    site = server.Site(tsAPIService.getResource())
    return strports.service(options['port'], site)
Пример #2
0
def makeService(options):
    """
    Make a service.

    @param options: The option parameters.
    @return: A service.
    """

    elAPIService = API(
        EDMLoggerAPI, utils.JSONLoadFromPath(options["haddockConfig"]),
        serviceClass=EDMLoggerServiceClass(
            utils.JSONLoadFromPath(options["config"]), reactor))

    site = server.Site(elAPIService.getResource())
    return strports.service(options['port'], site)
Пример #3
0
def makeService(options):
    """
    Make a service.

    @param options: The option parameters.
    @return: A service.
    """

    config = resource_string(__name__, "api.json").decode("utf-8")

    APIService = API(
        horsejaxAPI, json.loads(config))

    site = server.Site(APIService.getResource())
    return strports.service(options['port'], site)
Пример #4
0
    class v2(object):
        def __init__(self, outer):
            # `outer` is actually the a reference to the master `APIExample`.
            # You don't need to have `__init__` defined, but you can do stuff
            # here if you wanted to!
            # For example to migrate a processor from v1 to v2, you could do:
            # self.someapi_GET = outer.v1.someapi_GET
            pass

        def weather_GET(self, request, params):
            # Just return an object - Haddock will check it according to your
            # API definition and JSONise it. You'll notice that this is
            # different to what v1 returns - different processors can require
            # different things. Check APIExample.json to see what makes
            # Weather v1 and Weather v2 different.
            return {"temperature": 30, "windSpeed": 20, "isRaining": "YES"}


myAPI = API(
    APIExample, # Pass in your API class.
    json.load(open("APIExample.json")), # Load your API definition and give it
                                        # to Haddock to build your API with.
    serviceClass=myServiceClass()) # Rather than using the default, pass in an
                                   # instance of your custom service class.

service = myAPI.getApp() # Get a reference to the Klein app. You can also call
                         # `getResource()` to get a Resource, if you want that
                         # instead!
service.run("127.0.0.1", 8094) # Start up a HTTP server using Klein's helper.