Connecting front end to back end

Viewed 410

excuse my posting etiquette as I am new to stack overflow (and coding in general).

I have built a front end for a web app, using HTML,CSS, and Javascript. I have created a DB instance with Aws RDS using MySQL. I have successfully set up the database with the corresponding tables necessary for my webapp, but I am now stuck on how I actually interact between the front end and the back end.

I have done some research into a REST API, however finding competent learning material on the subject is harder than you'd think. Also, I don't need others to be able to access my data, just my client base.

I understand the basics of HTTP Requests, and I understand how to use MySQLI to get php files to interact with my database, but how should I get the relevant POST data into the PHP files to then have them push it to the database through MySQLI? How do I get the data retrieved via mysqli in PHP back to my web app?

3 Answers

I think you just need to complete your web application so for that, I would advice you to use any popular php framework either from Laravel or CodeIgnitor

Go learn the Getting Started, Database connection, Models, Controllers and View layer, it will give you controller to create your full web application. You won't need to use REST api for that.

You may want to use Laravel as the backend of your application. This will give you basic security issues fixed right out of the boxe and it's easy to get going.

https://laravel.com/

You can use the route/api.php file and create all the url and method for each of those requests.

Plus you can use Laravel passport to secure all the API call to use a JWT token so no ones can access the data if he's not connected.

Then the communication with your database will be very easy because Laravel is using Symfony.

https://symfony.com/

Other framework exists as well like CodeIgniter.

https://codeigniter.com/

I really think that for new developers using a framework is life saving especially for all the security issues you may have using your own PHP code.

Else using composer you can install any package that you may find interesting and time saving. Just make sure the package have a good community around it.

https://getcomposer.org/

Then to implement your API on you front-end you may want to use Axios.

https://github.com/axios/axios

And to test your API call before implementing them you may want to use Postman

I decided to go with a REST API, built in Node.js. I used express, json web tokens and a few tutorials from dev ed and traversy media to get started. Since originally posting, I have rebuilt both the front end and the API. I am now using normal HTML, CSS, and vanilla javascript on the front end, getting all the data from the API, which is pulling from the AWS RDS Instance of MySql.

Related