![]() Your API endpoints will rely heavily on Apache's re-write rules. +-+-+-+-+Įxit from the MySQL command-line interface. ![]() | product_id | product_name | cost_price | retail_price | Mysql> INSERT INTO products (product_name, cost_price, retail_price) VALUES ('WOOLEN SWEATER', '14.45', '18.00') Įnsure the records are in place by running a SELECT query against the products table. Mysql> INSERT INTO products (product_name, cost_price, retail_price) VALUES ('SUEDE SHOE', '24.00', '36.00') Mysql> INSERT INTO products (product_name, cost_price, retail_price) VALUES ('REXI BELT', '14.49', '18.85') Mysql> INSERT INTO products (product_name, cost_price, retail_price) VALUES ('SILVER COAT', '44.00', '60.00') mysql> INSERT INTO products (product_name, cost_price, retail_price) VALUES ('LEATHER JACKET', '89.23', '99.95') Populate the products table with some records. Product_id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, However, later in this tutorial, you'll learn how to expose this table information through a PHP API.Ĭreate the products table. Without an API, end-users accessing your web applications must go through a User Interface such as a web application or desktop software to get the product list. This table lists the currently available items for purchase in your hypothetical store, including their prices. MariaDB> GRANT ALL PRIVILEGES on store_api.* TO identified by 'EXAMPLE_PASSWORD' If you're using MariaDB instead of MySQL, use this command instead to create the user. Mysql> GRANT ALL PRIVILEGES ON store_api.* TO FLUSH PRIVILEGES mysql> CREATE USER IDENTIFIED WITH mysql_native_password BY 'EXAMPLE_PASSWORD' ![]() You will use this user's credentials to connect to the MySQL database in your PHP code. After you get the mysql> prompt, issue the command below to create a store_api database. $ sudo mysql -u root -pĮnter the root password of your MySQL server and press ENTER to proceed. SSH to your server and run the command below to log in to the MySQL command-line interface (CLI). This guide works fine with either the MySQL or the MariaDB server. Prerequisitesīefore you begin following along with this tutorial, ensure you have the following:Ī LAMP Stack. ![]() When you complete this guide, you should call your API endpoints to retrieve products from your database without going through a GUI. In this guide, you'll create an open JSON REST API for your hypothetical online store with PHP on Ubuntu 20.04. Also, when your API endpoints return data in JavaScript object notation (JSON) format, it can be used by mobile, desktop applications, tablets, and embedded devices without changing the code in the backend. In this case, consumers accessing your application will use dedicated URL endpoints to submit and query data without going through your application's graphical user interface (GUI).Ĭreating an API for your application allows end-users to integrate your services flexibly, leading to a better user experience. Companies including Vultr, Google, Facebook, and Twitter have a public API. Another use-case of an API is to open your popular application to the end-users. For instance, if you're developing a mobile application that uses a cloud database, you may create a PHP API to interface the Android client to a remote MySQL database. An application programming interface (API) is a middleware that allows two applications to talk to each other through a representational state transfer (REST) channel.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |