neomerx/json-api

How to replace the removed CodecMatcher?

Ilyes512 opened this issue · 12 comments

So I see CodecMatcher is deprecated on the releases page, but I don't see any information on why, what, why and how it's being "replaced" if at all?

I am trying to upgrade my app using v1 of this library. Should I implement this my self?

No you don't. On earlier stages of the spec developers planned to support multiple input formats with various Content-Type headers. And codec matcher served that purpose. Then they seemed to drop that idea and stick to JSON API MIME type. For this reason, it was dropped from the library.

Okey. Does the library contain a way to detect if the current request is one using the jsonapi spec?

According to this such a check would be something like

if ($request->getHeader('Content-Type') !== 'application/vnd.api+json') {
    return new EmptyResponse(415);
}
if ($request->getHeader('Accept') !== 'application/vnd.api+json') {
    return new EmptyResponse(406);
}

// seems to be OK

So really not much to add as a library feature 😄

Probably the only place where I can put anything from the lib is replacing application/vnd.api+json with MediaTypeInterface::JSON_API_MEDIA_TYPE

I found how they called it Extensions

Ok, and what about the removed psr7 adapter. I am using Laravel which uses symfony request object. There is a way of converting it using https://github.com/neomerx/json-api/blob/v1.0.9/src/Http/Request.php

Just wondering if this would still be enough or are you now (or possible in the future) going to use more psr7 methods (it used to be only 3 methods): https://symfony.com/doc/current/components/psr7.html

As you probably know Laravel has PSR7 support though it's likely to be slower than the wrapper from Limoncello.

It was needed only 3 methods. I think the old wrapper should work fine and very likely to be OK in the future. In the worst case you would need one more which is a couple of lines of code.

Sorry for dropping it. I thought nobody needed that.

I've rechecked the code and it appeared it doesn't require PSR7 at all :) So no need to maintain the wrapper and you can use Laravel requests. Sorry for the confusion.

Ah Nice. The packages used by Laravel to provide psr7 are the same packages mentioned in the link. Did not know they added psr7 support this way in laravel :)

Will continue working on implementing v2 of this lib in a few min. I should be able to get it going with the above info :) Thanks!

Btw, I've done some benchmarks recently for Lumen, Slim, and Limoncello. Though I've got no JSON API result to compare. Can please share some your performance results (e.g. swoole) that could be compared with any of them?

At the moment I only have one problem and thats with EncodingParameters class. I miss the fallowing methods (that used to be in it):

  • getPaginationParameters
  • getFilteringParameters
  • getSortParameters
  • getUnrecognizedParameters

It was nice to have one class to ask for all parameters. Now I need to implement my own.

Pagination, filters, and sorts are needed for fetching data from a database and not needed for the conversion. For this reason, they were removed.

If you use it for parsing input parameters and non-conversion tasks you can either have a look at how it is used in Limoncello Parser or consider using Limoncello App which does many other things as well.

@Ilyes512 If you have any further questions don't hesitate to ask.