Having an JSON support is application is not a new thing anymore.
If you have well developed application it should not be that hard to add the JSON support.
Following are the steps to have JSON support in your application:
- Every request made to the application through JSON must have application/json as Accept header. Most of the libraries like vue-resource or axios have this implemented.
- Disable your VerifyCsrfToken MIddleware. You can do it in app/Http/Kernel.php.
- Are each return of your controller, do this
- Of course, response()->json() needs appropriate status code and response content.
- It means if request wants response to be in json, we should respond in json other wise it can either be view or redirect depending upon your condition on what needs to be done.
Now, you need to make login system. To do this, use Json Web Token. What it does basically is, it returns a token based upon the credentials your provided which has encrypted information about the user.
Therefore, next time you make an request to the application with this token, application will be easily able to recognize you.
This is just a trick, if you are trying to convert your old applications to JSON support.
Everything is awesome.