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

usajack's avatar

How can i implement lumen api to views php pages?

Hello,

https://coderexample.com/restful-api-in-lumen-a-laravel-micro-framework/ I'm new to Lumen. I just finish this tutorial about creating a book store. I use GET, POST, PUT and DELETE methods. I tested it in CURL and all are working fine. I learn a lot form it!

I have a problem. I don't know how to integrate this API in resources/view/index.php I want to use 3 forms to take the data, to post the data to another resources/view/webpage.php and to update data. I don't wish to use vue.js, just php and css design!

I need an example!

0 likes
13 replies
Gog0's avatar

What was your goal making an API? You need to consume your API somehow, that's why people use JS frameworks like Vue or any other so the client side app just deals with the data serverd by the API.

However if you want you still could use cURL or Guzzle (which is using cURL) in your PHP controllers to request your API and then pass the returned data to a view.

I'm just not sure why you would do that.

1 like
usajack's avatar

How many ways to consume this lumen API exists? I have a full lumen application example consuming a VUE framework and is great. Let's say if i want this to be consumed on the same default lumen installation how i will do that? without using VUE or cURL or Guzzle. What parts of the api must be request to return data to a view? I need a tutorial or an example how to make the connexions between my API and a framework that will consume it! Can laravel framework to consume the lumen API? If yes, how i will do that?

ohffs's avatar

If you don't want to use something like vue, curl or guzzle you are going to be quite limited. You can do an http 'get' using file_get_contents() - but you're kind of shooting yourself in the foot not taking advantage of curl etc.

usajack's avatar

I understand now! So if i create an API on: example: Lumen, Laravel, etc. other frameworks this will be the BACK-END coding! To make a user interface - the views pages i will need a FRONT-END framework like vuejs, angular, etc. which will consume the API. I am right?

Gog0's avatar

Yeah that's it. Lumen is designed to make APIs, meaning processing/retrieving datas to provide services to clients (frontends).

If you don't care giving easy access to your datas to various clients (you could have a website, mobile apps or other people's websites using your API), having an API might not make much sense. Having a full Laravel application returning the rendered views is not something bad.

Making an API or not doesn't have an obvious answer, it will depend of your needs and what you're trying to achieve.

1 like
usajack's avatar

"Having a full Laravel application returning the rendered views is not something bad", from your experience what will be great?

"If you don't care giving easy access to your datas to various clients" For that i will include encryption methods, user accounts, authentication system. I will try to make a small ecommerce website just for get skills in coding!

Here is an example how the LUMEN, VUE & jQuery are working together. https://unnikked.ga/a-guestbook-using-lumen-and-vue-js-6efe705a2c26?gi=51cee3184057

jekinney's avatar

Full laravel. Older versions of lumen had views btw but has been removed as it's not the intent of lumen.

Yes, lumen is faster, but that's because its bare minimum. As you start adding core features that speed becomes irrelevant. And you end up with a laravel type of framework anyways.

Laravel can be easily modified to speed up performance. Just in the conf/app.php alone you can comment out features and facades you don't need so they don't boot up with each request. Which is at the core lumen does is not use a lot of features and a simpler router. Not sure about the newest release, but lumen 5.1 had the entire laravel files under vendor minus some third party packages and as you could add features back. But as stated then your differences is negligible.

1 like
jekinney's avatar

Oh! Weird test but I get it now. Makes sense now. Just testing your building anAPI knowledge and consuming it it a laravel app.

Two apps obviously. So basically testing both knowledge sets.

Actually quite common on an enterprise level where a company has an API for sub applications to use. Matter of fact my current contract utilizes a lumen API for employee and non-employee login and profiles consumed by internal and external sites.

Two tables but globally accessable by API keys.

1 like
usajack's avatar

I know how to build the API in lumen but i don't know how to integrate it in laravel platform to be consumed with FRONT-END rendering views. And for this i cannot use VUE.js!

beerbuddha's avatar

Your question stem from API principles and not lumen vs

You have over-engineered this. As everyone has pointed out that there are many way to consume the API which is something that you failed to grasp.

In basic web design: you have data (unless you have a static page which has static data), then you have the html + css to render the webpage.

In Laravel your views are your html + css, and then you have Eloquent (or enter DB source like mongo, etc) that fetches data for you.

Now in API design (can be in any language) that fetching component just like Eloquent is where your API comes in. The API service is your data source and platform to serve your data.

Each platform / language has different way to consume the data that you have provided. Angular / Vue /jQuery are data binding frontend end platform. You can have a PHP application that in turn uses curl to call your API service (guzzle is a popular wrapper). You could have NodeJs as a servelet web application being your middleman that actively consume and communicate your data source.

As @jekinney and @Gog0 mentioned - Lumen is your delivery service for the API, now you need another application to consume it.

As others pointed out - you could import in views to the lumen, but then if you do that, you might as well have a full Laravel application. If your application holds both api + views - it maybe best to learn some frontend to abstract your backend (api service).

tutorials on the internet usually separate API from consuming it because it will depending on how you want to consume it. ie: a stripe API is for processing, where as google api can be for many types of services, etc.

Since you are new to this playing field: why dont you experiement with having two different PHP application as a starting ground rather than ask us for best way: 1 lumen api, and 1 plain php that just calls your end points and renders the data afterward and see the limitation. If it fits, maybe its good enough - then move towards frontend or utilize everything in one application.

Time is irrelevant because if we tell you to pair it with javascript you will spend time trying to understand javascript. So my suggestion for you is 1) understand what is an API and how to utilize it and why applications uses it 2) continue using PHP as your view rendering system by pairing it with any framework that renders PHP into HTML (laravel itself does it through blade) and self call your API.

Gog0's avatar

Well if it's a job interview task I guess you kind of have to do it that way then. So you know how to make your Lumen API which is great.

So apparently what you need now is a Laravel app which is making use of your API and again I would recomend you using Guzzle. Check HERE for a quick install and very basic usage and HERE for complete documentation.

With this library you could easily make calls to your Lumen API in your Laravel app Controllers and then pass the responses to your Laravel views.

Also using Laravel doesn't mean not using Vue as Laravel provides everything from database connection to rendering views with Blade. So you could use Vue in your views and it would still be a Laravel application. The controllers could call your API instead of having ajax requests like in your guestbook example and you could still want to use Vue to make components even if not making a full Vue app with doing routing or authentication on the client side for example.

Even if it's a common scenario to have a dedicated API as a backend and a JS app as a frontend. it could make sense to consume a Lumen API from the Laravel backend if for example a company wants to have an API which is shared across other applications using Laravel having their own purpose, thei own databases, etc. If the Laravel app is meant to be more than just a frontend then it could be a reason.

You seem a bit confused about what you should do and I think you really need to stop thinking Laravel/Lumen/JS or any other thing for a second and just think about what an API is for, what are the pros and cons and when you should have one. It's actually kind of hard to understand what you want as you don't really seem to know yourself. It's all about the needs! Do you have any more information about this job interview task so we could maybe help you understand better what's actually needed here?

usajack's avatar

Here is more information about the job interview! For the back-end is lumen api use methods like GET, POST, PUT, DELETE, PATH & TOKEN.

  1. authentication system with login, register, forget password. I have examples for this.
  2. for advertising - will be something like GuestBook example but with multilanguage & currency included.

For the front-end will be laravel. I use xampp with php & mysql. I have lumen istalled on htdocs/lumen. I must install laravel for the front-end on htdocs/laravel to consume the api.

What i need is an example. Now i'm trying to hook GuestBook to laravel just for testing and learning how the api is consumed and rendered. But nothing for now. If i will do it then i know all the informations i need to create the job app from the beginning to finish.

Please or to participate in this conversation.