Provides transport-independent abstractions for media-typed content representations.
A representation associates encoded data with metadata describing that data. A parser selects an interpretation according to the representation's media type:
require "protocol/content"
require "json"
parser = Protocol::Content::Parser.build do |parser|
parser.register("application/json") do |representation|
JSON.parse(representation.body.join)
end
end
JSONRepresentation = Protocol::Content::Representation[parser]Representations can be constructed symmetrically from request and response messages. The message only needs to expose headers and body:
representation = JSONRepresentation.for(request)
representation["user"]["name"]
representation = JSONRepresentation.for(response)
representation.valueParsing is lazy and memoized by each representation. Registered handlers receive the complete representation so they can inspect media-type parameters or stream the body when appropriate.
Please see the project releases for all releases.
We welcome contributions to this project.
- Fork it.
- Create your feature branch (
git checkout -b my-new-feature). - Commit your changes (
git commit -am 'Add some feature.'). - Push to the branch (
git push origin my-new-feature). - Create a new pull request.
To run the test suite:
bundle exec susTo make a new release:
bundle exec bake gem:release:patch # or minor or majorIn order to protect users of this project, we require all contributors to comply with the Developer Certificate of Origin. This ensures that all contributions are properly licensed and attributed.
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment or harmful behavior is not tolerated. If any issues arise, please inform the project maintainers.
- protocol-http provides HTTP message abstractions.
- protocol-media provides media type abstractions.
- async-rest provides asynchronous REST client abstractions.