Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ZetecVan's avatar

Consuming an internal API with Spark.

I am using Vue Tables 2 to call an internal API to list some data. I want the API to retrieve more data for logged in users (ie: some values are to be unavailable to non-logged in users, to encourage them to sign up).

In the Spark docs there is this:

Spark makes it entirely painless to consume your API in this way. Simply make requests to your > API routes using your JavaScript framework as normal. You do not need to pass any token or credentials. All of the authentication will be handled automatically by Spark, which generates "transient", short-lived API tokens behind the scenes automatically when users load your application's pages. These API tokens are automatically refreshed in the background by Spark.

I remember seeing a video a while ago where (I think) Taylor demonstrates this functionality. Can anyone point me in the direction of the video, or suggest any way to do this.

0 likes
4 replies
ZetecVan's avatar

Thanks @cronix. I thought it was that one before I asked, but it's not. I'm sure in the one I was thinking of he did something in the controller to show whether it was authenticated or not. Like a Auth::user().... although I could be imagining the whole thing...

douglas_quaid's avatar

@ZetecVan this was me about a month ago with Spark. Just a word of advice, you should download the sample spark application that Taylor built for a basic ToDo application. You will see how to all works by looking at the views, routes, event listeners, vue.js, and ajax calls.

https://spark.laravel.com/docs/4.0/quickstart

Scroll to the bottom for the demo download link. Unfortunately it's for an older version of Laravel, but you can port it over to a fresh install of 5.4. That's what I did!

christophrumpel's avatar

Anything new here? Having the same problem with unauthorized. The demo app is a little outdated, no current laravel version and using other vue stuff for making the requests.

Please or to participate in this conversation.