REST API sending webhooks to front end - spring

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

Related

SendBird Laravel API with React Front End

I have a Laravel back end serving APIs to a React front end for a solution I am developing. I want to integrate SendBird Chat API into the application to allow authenticated users to chat with each other.
My query is, how can I pass authenticated user details to SendGrid? I.e., if user X and user Y both log into the website, how do I allow them to talk to each other?
I am pretty sure I've misunderstood something around sessions but any help is appreciated.
I am not looking for a specific code answer but a general architectural answer.
You send request from your frontend app, Laravel API receives request, builds whole application (all of your code) to process it and returns response. That is one request lifecycle and Auth::user() is going to be the user which sent request.
Request lifecycle explains this in much more detail but I recommend first learning about the basics of Client <-> Server architecture

How to broadcast real time events to external application

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?

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.

Writing A Bot Framework Client

I've been away from BotFramework development for a while and have now come back to it.
I am using this Bot hosted internally within my company, and talking to it using a relay application using REST. This all worked fine.
However, after updating to V3 of the Bot Framework I came across issues. I see that the changes mean that the Bot now replies asynchronously, sending data to the ServiceURL field. Therefore I have a couple of questions.
Can I still use this architecture for the Bot Framework? (i.e. hosting internally to the company, without using Azure or Connectors)
If I can, I assume that my relay application will need to have an endpoint that the Bot can reply to? Does it just do a http POST to the ServiceUrl I give it? (i.e. http://mybotserver:9000) or is it posting to a URL under that server address? I assume the body of the post is the usual Json you see in the Channel Emulator.
I don't know the specifics of your architecture, but in general, if your bot (via relay) can:
Reach the ServiceURL endpoint with an https post
Receive incoming requests to an endpoint you registered with the Bot Framework
The relay needs to be able to reach our login service to sign requests
Also needs to be able to reach our OpenId endpoint as part of signing/authenticating
That should be it.

Api and consumer flow

I am developing an API for a social network website. This API will basically get all the requests from the users (get friend list, post a status update etc) and reply back if necessary.
We will implement OAuth 2.0 protocol for authentication. Consumer (our php project) has API id and secret.
Basic scenario:
Client wants to log in
API Consumer (php web project) takes this request, directs user to API
User send his/her user credentials to the api, gets the token.
User comes back to our website, pass token to the consumer.
Consumer goes to the api server, gets the access token.
Now consumer (php project) has access to user's private information.
Since this is a social network website, we want app developers to be able to use our API in the future.
I am not experienced in API-design. Does that flow make sense? I guess the simplest authentication would be accessing user information through php project. But we don't want to access database in php code. We will use ajax in client side and send a request to the API. And I believe there should be a better solution, what would you suggest?
Sure, API design is basically point where you need to choose technology.
Either it can be PHP or .net or Java.
I would prefer either PHP or .Net as we get lot of flexibility in it.
API will return XML or Json depending upon the request.
There are lot of CMS in php which can be helped.
.net we have Service Stack to help you.
API's had to be fully independent from other world as well as within API method as well.
If you are able to achieve this, then you will surely create a good architecture.

Resources