- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create Web API service in PHP?
SOAP and REST APIs are the widely used APIs.
Consider the presence of a PHP class named manage.php that helps in managing the entries in a database.
class manage { private $entryId; function __construct($entryId) { $this->entryId = $entryId; } function deleteEntry() { //delete $this->entryId from database }}
On the server, this functionality can be accessed as shown below −
require_once('manage.php'); $m = new manage(12); $m->deleteEntry();
How can this be accessed by a different server? A third file can be created that will behave like a buffer/an interface that helps access this data. Below is a sample buffer −
Let us call it ‘api/delete.php’
require_once('manage.php'); if(hasPermission($_POST['api_key']) { $m = new manage($_POST['entry_id']); $m->deleteEntry(); }
Users can send a POST request to the server at http://example.com/api/delete.php with an api_key and an entry_id.
- Related Articles
- Using SAP Web Service from SAP by PHP with parameters
- How to Create Background Service in Android?
- Consuming Web Service in C# application (SAP)
- What is Web Service in information security?
- How to do Web API versioning with URI in C# ASP.NET WebAPI?
- How to host a web-service using IIS (windows) and .net
- Integrating JSession in a Web-Service in SAP
- Calling SAP Web Service to get data in Flash dashboard
- How to Create Fullscreen API using JavaScript?
- Using SAP Gateway service in SAP Web project
- Using SAP Web Service from WSDL file
- SAP BI retrieving PDF from Web Service
- Invoke a Web service from AJAX in SAP application
- Error while calling Web Service using SRT_UTIL Transaction
- Naming conflict error while consuming SAP Web Service in .net

Advertisements