Beispiel #1
0
import jwt
from space_api import API, COND

api = API('demo', 'localhost:8081')
SECRET = 'my_secret'
api.set_token(
    jwt.encode({
        "password": "******"
    },
               SECRET,
               algorithm='HS256').decode('utf-8'))
db = api.my_sql()

service = api.service('login_service')


def login(params, auth, cb):
    response = db.get_one('demo_users').where(
        COND("username", "==", params["username"])).apply()
    if response.status == 200:
        res = response.result
        if res["username"] == params["username"] and res["password"] == params[
                "password"]:
            cb(
                'response', {
                    'ack':
                    True,
                    'token':
                    jwt.encode(
                        {
                            "username": res["username"],
Beispiel #2
0
from space_api import API
import variables

api = API(variables.app, variables.url)

service = api.service(variables.service)


def echo_func(params, auth, cb):
    cb('response', params)


# def func2(params, auth, cb):
#     cb('response', 'my_response')

service.register_func('echo_func', echo_func)
# service.register_func('func2', func2)

service.start()
api.close()
Beispiel #3
0
from space_api import API

api = API('books-app', 'localhost:4124')

service = api.service('service')


def echo_func(params, auth, cb):
    cb('response', params)


def func2(params, auth, cb):
    cb('response', 'my_response')


service.register_func('echo_func', echo_func)
service.register_func('func2', func2)

service.start()
api.close()
Beispiel #4
0
from space_api import API

api = API('books-app', 'localhost:4124')


def my_func(params, auth, cb):  # Function to be registered
    print("Params", params, "Auth", auth)

    # Do Something
    cb('response', {"ack": True})


service = api.service('service')  # Create an instance of service
service.register_func('my_func', my_func)  # Register function
service.start()  # Start service

# Call function of some other service
response = api.call('some_service',
                    'some_func', {"msg": "space-service-go is awesome!"},
                    timeout=5)
print(response)

api.close()