Skip to content

Add ability to use custom serializer and deserializer #125

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jul 8, 2020
Merged

Add ability to use custom serializer and deserializer #125

merged 1 commit into from
Jul 8, 2020

Conversation

deptyped
Copy link
Contributor

@deptyped deptyped commented Jul 8, 2020

Now all you have to do to change the serialization or deserialization is pass the function to the dispatcher, like this:

import ujson
from flask import Flask, request, Response
from jsonrpcserver import method, dispatch

app = Flask(__name__)


@method
def ping():
    return "pong"


@app.route("/", methods=["POST"])
def index():
    response = dispatch(request.get_data().decode(), serialize=ujson.dumps, deserialize=ujson.loads)
    return Response(str(response), response.http_status, mimetype="application/json")


if __name__ == "__main__":
    app.run()

Copy link
Member

@bcb bcb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bcb bcb merged commit 8f3437a into explodinglabs:master Jul 8, 2020
@bcb
Copy link
Member

bcb commented Jul 8, 2020

Thanks @deptyped 👌

@deptyped deptyped deleted the feature/custom-serializer-deserializer branch July 8, 2020 14:28
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants