laravel icon indicating copy to clipboard operation
laravel copied to clipboard

Is there a way to consume the api's without an actual http request ?

Open minamassoud opened this issue 3 years ago • 10 comments

Something like the tests $this->jsonapi()->get('/api/v1/posts') but to be used within the app, like maybe \JsonApi::server('v1')->get('api/v1/posts') which will return the json response content ?

minamassoud avatar Dec 21 '21 15:12 minamassoud

Thanks for raising this. I definitely intended to do something like this to allow you to get JSON:API documents outside of a HTTP request, but didn't get round to adding it. It's just a matter of wiring up a few different parts of the package behind a fluent interface, and then documenting it.

lindyhopchris avatar Dec 21 '21 18:12 lindyhopchris

Really looking forward to this

RaymondAtivie avatar Feb 28 '22 16:02 RaymondAtivie

Useful feature, looking forward to getting this update as well.

vrusua avatar Mar 11 '22 06:03 vrusua

This is exactly what I need!

carlosjac avatar Jun 27 '22 11:06 carlosjac

Ok great, looks like a few people need this so will try to prioritise this.

Out of interest, are people expecting it to be authorised and validated? At the moment that's coupled to a HTTP request due to the way Laravel's form requests work. Or are you not expecting authorisation/validation?

FYI in a future version I'm going to have to decouple authorisation and validation from the HTTP request, so that we can support JSON:API Atomic Operations - but I'm not quite at that stage yet.

lindyhopchris avatar Jun 27 '22 14:06 lindyhopchris

@lindyhopchris Thank you very much for paying attention to this request.

In my case, I don't need validation nor authorization because I'll use it from my controller which is already authorizated and validated.

Greetings

carlosjac avatar Jun 27 '22 19:06 carlosjac

I'm also interesting that feature.

bbprojectnet avatar Aug 01 '22 11:08 bbprojectnet

Yeah this is likely to be something I work on soon - as I need to decouple everything from HTTP requests to prepare for Atomic Operations, which I'm super excited to use (and is a feature that's been frequently requested!)

lindyhopchris avatar Aug 01 '22 11:08 lindyhopchris

Yes, i'm also looking forward to atomic operations :)

bbprojectnet avatar Aug 01 '22 11:08 bbprojectnet

In the linked testing issue (which isn't a problem with testing), the solution was to provide the server name to the facade when getting the resource container; however then you also needed to call withServer() on the resource class and give it the same server name.

If a container is derived from a particular server, it should either inject the server throughout whatever it creates, or at least inject the server name - so that any other server dependencies are derived from the same server as the container originated.

lindyhopchris avatar Oct 31 '23 13:10 lindyhopchris