예제 #1
0
from examples import load_api
import pyservice

client = pyservice.Client(**load_api('echo/api.json'))


def main():
    response = client.greet(name="Joe", city="Seattle")
    print(response.greeting)
    print(response.question)

    try:
        client.echo(value="this will throw auth failure")
    except client.exceptions.Unauthorized:
        print("Must provide credentials to call `echo`.")


if __name__ == "__main__":
    main()
예제 #2
0
from examples import load_api
import pyservice

client = pyservice.Client(**load_api('echo/api.json'))


def main():
    response = client.greet(name="Joe", city="Seattle")
    print(response.greeting)
    print(response.question)

    try:
        client.echo(value="this will throw auth failure")
    except client.exceptions.Unauthorized:
        print("Must provide credentials to call `echo`.")

if __name__ == "__main__":
    main()
예제 #3
0
from examples import load_api, basic_wsgi
import pyservice

service = pyservice.Service(**load_api('echo/api.json'))


@service.operation("greet")
def greet(request, response, context):
    name = request.name
    city = request.city
    if not name:
        raise service.exceptions.InvalidName("Surely you have a name!")
    if not city:
        raise service.exceptions.InvalidCity(
            "Please tell me where you're from.")
    response.greeting = "Hello, {}!".format(name)
    response.question = "How's the weather in {}?".format(city)


@service.operation("echo")
def echo(request, response, context):
    response.value = request.value


# Let's add a plugin for auth.  This is an "operation" scope because we need
# access to the operation parameters.  The "request" scope is for pre/post
# plugins, that need to ensure the request has been serialized before they
# close (such as sqlalchemy)

# For now we'll only authenticate calls to the echo operation,
# with some super secret credentials