How to broadcast real time events to external application - laravel

I'm working on a project where Laravel is the back-end and front-end is a ReactJS. I'm responsible for back-end only and we are building back-end as a restful api, so I'm using sanctum to authenticate user, there are no sessions, stateless flow. Now I need to implement a real time in web notifications. I was thinking about using Laravel Broadcasting: Redis + Laravel echo server. But the problem is, that frontend is not made on laravel. Its a simple ReactJS SPA, that uses back-end as an API.
My question is what is the best way to implement this functionality? I guess listening to standard events from that ReactJS app is not going to work?

Related

REST API sending webhooks to front end

If my rest API has a webhook setup where it is getting information, how do I notify the front end that new information is received and is ready to be sent? Can the API only send data to front end if the front end requests it? Using Spring boot and Vuejs.
Well, I've never used Vue.js or Spring boot, but I'm familiar with React and since both are front-end libraries I believe they work similarly. I believe what you're looking for is Socket.io which will create a real-time, bidirectional and event-based communication between the client's browser and the server. So when you receive an event in your webhook you communicate whatever you want to the client.
Here is an example on how to build it using vue.js and Node.js, I'm sure you can tailor it to your needs.
https://medium.com/js-dojo/build-a-real-time-chat-app-with-vuejs-socket-io-and-nodejs-714c8eefa54e

Laravel separate backend and frontend

while building with Laravel probably you may have faced the same situation where you have a RESTful service with JSON replies and, at the same time, you need to have a frontend able to consume those APIs to offer a web interface.
Now, the most obvious solution would be to use Laravel Blade template engine and to diversify routes according to the address (/resource or /api/resource). However, this approach brings in an additional burden, directly reflected in controllers, where are you have to consider not only the reply itself but also whether it comes from a device or from the web interface and reply accordingly.
I have also seen a lot of frontends actually detached from the backend and built using serverless technologies such as Angular or React, so that both the web interface and the mobile app consume the same APIs and the backend can be much simplified.
Let's take as an example a "Uber for..." service consisting of a native app, a PWA and an admin interface (web), which approach would be the most advisable and why?

Consuming Laravel Passport API with javascript (React + Axios) from another application

I have managed to make run Laravel 5.4 and implemented the API Authentication (Passport).
What I would try to achieve is to make this as my API server and build React applications that would interact on this API.
Does this mean I have to make routes on routes\api.php?
Let's say I have a React app name requestform on development and running on http://127.0.0.1:8080. How will I consume an api route with axios or jquery?
I can't seem to make the correct keyword to search on google and all the samples I can get are the ones that the API and the javascript application is on the same domain.
This post may have been answered by now. But if not then...
I think you are in the right track..
Does this mean I have to make routes on routes\api.php?
Yes. Your API routes will depend on this file.
Let's say I have a React app name requestform on development and running on http://127.0.0.1:8080. How will I consume an api route with axios or jquery?
Make sure your API Server is running, say it's on http://server.dev, you can consume the API in another app by http://server.dev/api/[your-routes].
I can't seem to make the correct keyword to search on google and all the samples I can get are the ones that the API and the javascript application is on the same domain.
This is a matter of what front-end programming you know. You can use any javascript knowledge to consume your own API with the same domain. There is already a Vue integration packaged in Laravel 5.4+ or just plain vanilla javascript or jQuery.

Communicate between two Laravel apps

I need some suggestion and possibilities...
I have a product whose back-end is on Laravel 5.0 and front-end is built on Angular 2
Due to some SEO issues I am rewriting the front-end in Laravel.
Here I wanted to know that if I am creating new Laravel front-end app THEN how could I communicate/use/request my pre-built back-end APIs without using cURL for best I/O response time.

Django rest framework + ionic2 + django channels

I want to develop real time native application and considering using Django as backend and ionic2 as frontend. But through the research i realize that websocket is needed for the app to be real-time. And django channels is the option.
The question is "is it possible to combinate django rest framework, ionic2 and django channels altogether?" And additionally if I try to implement push notification using cordova plugin, could it be also work altogether? I know this question is quite bad but I am quite a beginner so i want to know before trying this approach..
any advice will be great for me, Thanks buddies in advance!
Yes, it is.
Ionic is going to be only a consumer of your Django-rest-framework API and your Django services. In other words, the front-end can be in any technology you want.
On the other side, Django-rest-framework + Channels work perfectly together. They are supposed to be. I've recently built a project with those technologies and I can guarantee that there is a perfect separation between the asynchronous processes and the typical Django HTTP runserver process.

Resources