{"action":"created","issue":{"url":"https://api.github.com/repos/manyminds/api2go/issues/119","labels_url":"https://api.github.com/repos/manyminds/api2go/issues/119/labels{/name}","comments_url":"https://api.github.com/repos/manyminds/api2go/issues/119/comments","events_url":"https://api.github.com/repos/manyminds/api2go/issues/119/events","html_url":"https://github.com/manyminds/api2go/pull/119","id":80758603,"number":119,"title":"Added ContentMarshaler interface","user":{"login":"jblazquez","id":5482684,"avatar_url":"https://avatars.githubusercontent.com/u/5482684?v=3","gravatar_id":"","url":"https://api.github.com/users/jblazquez","html_url":"https://github.com/jblazquez","followers_url":"https://api.github.com/users/jblazquez/followers","following_url":"https://api.github.com/users/jblazquez/following{/other_user}","gists_url":"https://api.github.com/users/jblazquez/gists{/gist_id}","starred_url":"https://api.github.com/users/jblazquez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jblazquez/subscriptions","organizations_url":"https://api.github.com/users/jblazquez/orgs","repos_url":"https://api.github.com/users/jblazquez/repos","events_url":"https://api.github.com/users/jblazquez/events{/privacy}","received_events_url":"https://api.github.com/users/jblazquez/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-05-26T02:53:39Z","updated_at":"2015-05-26T08:02:57Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/manyminds/api2go/pulls/119","html_url":"https://github.com/manyminds/api2go/pull/119","diff_url":"https://github.com/manyminds/api2go/pull/119.diff","patch_url":"https://github.com/manyminds/api2go/pull/119.patch"},"body":"Hi,\r\n\r\nFor your consideration here's a proposed new extension point for `api2go` that allows a user of the library to support encodings other than JSON for requests and responses while still being able to take advantage of the autogenerated routes.\r\n\r\nThe motivation for this change is to allow for higher-performance communication with clients that can speak binary formats that are more optimized than JSON, such as [CBOR](http://tools.ietf.org/html/rfc7049) or [MessagePack](http://msgpack.org/). Coupling these formats with HTTP/2 support can yield significant performance improvements for chatty JSON APIs.\r\n\r\nThe extension point consists of one new interface and one new `API` constructor:\r\n\r\n```go\r\ntype ContentMarshaler interface {\r\n  Marshal(i interface{}) ([]byte, error)\r\n  Unmarshal(data []byte, i interface{}) error\r\n}\r\n\r\nfunc NewAPIWithMarshalers(prefix string, baseURL string, marshalers map[string]ContentMarshaler) *API\r\n```\r\n\r\nBy default the behavior of the library is exactly the same as before: only JSON encoding is supported. However, if the user provides a marshaler for a `Content-Type` other than the standard `application/vnd.api+json` then a client that sends an `Accept` header including that content type will be responded to using that format instead of JSON.\r\n\r\nThe changes to the library are small because the `jsonapi` subpackage needed no changes at all. It already provided all the necessary support with the general `Marshal` and `MarshalWithURLs` functions. Only the main API implementation had to change a little to pass around some additional context to allow for the right marshaler to be selected.\r\n\r\nThe existing unit tests provided good test coverage and ensured that no regressions for the default JSON encoding happened. I extended the CRUD example to show how the new extension point could be used.\r\n\r\nThanks."},"comment":{"url":"https://api.github.com/repos/manyminds/api2go/issues/comments/105434413","html_url":"https://github.com/manyminds/api2go/pull/119#issuecomment-105434413","issue_url":"https://api.github.com/repos/manyminds/api2go/issues/119","id":105434413,"user":{"login":"sharpner","id":574362,"avatar_url":"https://avatars.githubusercontent.com/u/574362?v=3","gravatar_id":"","url":"https://api.github.com/users/sharpner","html_url":"https://github.com/sharpner","followers_url":"https://api.github.com/users/sharpner/followers","following_url":"https://api.github.com/users/sharpner/following{/other_user}","gists_url":"https://api.github.com/users/sharpner/gists{/gist_id}","starred_url":"https://api.github.com/users/sharpner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharpner/subscriptions","organizations_url":"https://api.github.com/users/sharpner/orgs","repos_url":"https://api.github.com/users/sharpner/repos","events_url":"https://api.github.com/users/sharpner/events{/privacy}","received_events_url":"https://api.github.com/users/sharpner/received_events","type":"User","site_admin":false},"created_at":"2015-05-26T08:02:57Z","updated_at":"2015-05-26T08:02:57Z","body":"I'm sold. Since this refactoring mostly decouples the implementation it won't hurt. What do you think @wwwdata ?"}}