snippetMinor
How to serve RESTful APIs?
Viewed 0 times
apisserverestfulhow
Problem
Background:
I am developing a Web application for Employee Management. I use
My problem:
I am confused on how to deploy my application. My current plan is to use the command
Some other thoughts:
As far as I know about
I am developing a Web application for Employee Management. I use
Laravel for building a RESTful API, and (maybe) ReactJS for the frontend.My problem:
I am confused on how to deploy my application. My current plan is to use the command
Laravel artisan serve for the RESTful API, and use Nginx for serving HTML files. But is Laravel artisan serve possible for production? How to serve RESTful API?Some other thoughts:
As far as I know about
Node.js applications. We can use ExpressJS for building a RESTful API, then pm2 start app.js for production. But Node.js is good at serving dynamic contents. If I build the RESTful API with Laravel or Spring Boot, or Ruby on Rails (Sinatra), I don't think a command like pm2 start app.php (app.java or app.rb) will work (here pm2 is only for convenience, I know it is only for a Node.js app) because PHP, Java or Ruby is quite different from Node.js. I am afraid I am missing something fundamental here.Solution
The confusion might come from the concepts behind the tools you are using. So let's start with a little definition.
Laravel and Artisan
Laravel
Framework for building a full MVC Web application in PHP. It is the equivalent of Spring-boot with Java or Rails with Ruby.
Artisan
Laravel's console driven interface for development. It provides tools such as the web server coming with PHP 5.4+. When using the "serve" command a simple web server will start. This is perfect for development, but I would suggest you use a server that gives you proper configuration flexibility in production such as Apache or nginx.
Your other thoughts
Java/Ruby/PHP/Javascript
Are programming languages. Node.js is like an ecosystem that allows you to run client/server/middleware/tools Javascript based applications. Someone did a great job of comparing it with a Java ecosystem. Right here.
But is
In theory, yes. It would require your development setup to be in production as well. Hence from this assertion, the answer becomes self evident for security, operability, configuration and performance to name a few. You will need a different configuration for production.
How to serve RESTful API?
No matter which language you use, choose a library or a framework that will give you the tools to implement your APIs. Since Laravel is your framework, you can take a look at this tutorial to get started.
Laravel and Artisan
Laravel
Framework for building a full MVC Web application in PHP. It is the equivalent of Spring-boot with Java or Rails with Ruby.
Artisan
Laravel's console driven interface for development. It provides tools such as the web server coming with PHP 5.4+. When using the "serve" command a simple web server will start. This is perfect for development, but I would suggest you use a server that gives you proper configuration flexibility in production such as Apache or nginx.
Your other thoughts
Java/Ruby/PHP/Javascript
Are programming languages. Node.js is like an ecosystem that allows you to run client/server/middleware/tools Javascript based applications. Someone did a great job of comparing it with a Java ecosystem. Right here.
But is
Laravel artisan serve possible for production?In theory, yes. It would require your development setup to be in production as well. Hence from this assertion, the answer becomes self evident for security, operability, configuration and performance to name a few. You will need a different configuration for production.
How to serve RESTful API?
No matter which language you use, choose a library or a framework that will give you the tools to implement your APIs. Since Laravel is your framework, you can take a look at this tutorial to get started.
Context
StackExchange DevOps Q#2737, answer score: 2
Revisions (0)
No revisions yet.