How to use laravel application as both web application and Rest API - laravel

I am implementing a laravel web application and I separately implementing a native mobile application as well. I need to use the same backend which I use for a web application for mobile application as well. How can I implement the backend as a REST API which can be called from a mobile application and also use for the web application as well?

there's a file located in routes/api.php.
You can store your API there like the way you implement your routes at web.php. But return JSON from your controller for your REST API.
you can call it like http://yourdomain/api/yourroute

Related

How to call Rest request from jsp

I have to create 2 projects. Web Service and one is Web project.
I created the web service using Rest in spring boot and web project using dynamic web project using Jsp and servlets.
Now I have to consume the web service in web project. How can I do ?
You can do AJAX call from your JSP side to your REST server side using Javascript. You can also use library like JQuery or axios (there MDN versions since you are using JSP) to send REST API calls to your same or any other server. You can follow https://stackoverflow.com/a/44859872/8684299 this answer.

Create a web application using Spring framework for back-end but without using Spring MVC.s

I want to learn the Spring Framework and therefore I decided to make a web application using it, but I don't want to use Spring MVC as it still uses JSP. What all projects from Spring can be used if I want to have a UI which can be made using React / Angular and the backend is managed by Spring.
You have to use REST API, and pass data to front-end JS framework via JSON.
Look here: https://spring.io/guides/gs/rest-service/
Start with creating a simple Rest Controller with Spring Boot.
Then you have to choose your JavaScript framework (jQuery, Angular, React),
and make a HTTP request to URL typed in your #RestController.
You can achieve this by using AJAX method from your JS framework.
Try this,it will speed up your development
Restful Web Service with Spring Boot
by the way,if you want to use Angular/React+Spring Boot you can use JHipster, this tool will just do the basic setup for your Angular/React+Spring Boot application in couple of minutes,the website has a clear video tutorial you can use it will only take about 15 min approx
Jhipster

How enable Angular Universal with a Java/Spring backend?

I have an app, where backend implements on Spring using Spring Boot and front-end side use Angular2. Can somebody help me and explain how to integrate Universal using Java becken. Or show me a good example how I can do that.
how to integrate Universal using Java beckend?
You cannot do that directly as universal needs a different server side technology -nodejs
But you have a another (better) solution
Spin off a separate nodejs app for the angular and universal then route all the API calls through the nodeJs to your Spring boot application. Now your spring boot application will be just a (micro)service which will only deal with the data, not the presentation (markup/style etc)

what's the best way to secure rest web services using spring?

What is the Best way to secure REST Services (develop by Spring Framework) for use in Android app? Please consider the limitation of httpclient in android. using http authentication header is enough?
My need is to be able to control which application is calling my web service and is this application authorized to call it.

Using both Anonymous and Windows Authentication in ASP.NET Web API

I've implemented an ASP.NET Web API application having one regular controller (HomeController) and several other Web API controllers. I have already the handled authentication for the API controllers (using anonymous authentication together with custom authorization attributes), but i want to restrict the access to the MVC controller and all its actions using Windows Authentication, without affecting the rest of the controllers.
Is it possible to achieve this? Can Windows and Anonymous authentication be mixed is such a way in a Web API application?
Note: the application will be hosted in IIS.

Resources