Software’s for you

we will prefer you the best

Best Offers




Objective :

In this post we are going to discuss about simple RESTApi service using php,mysql and json.

What is RESTArchitecture?

REST stands for REpresentational State Transfer. REST is a web standard based architecture that uses HTTP Protocol. It volves around resources where every component is a resource and a esource is accessed by a common interface using HTTP standard methods. REST was first introduced by Roy Fielding in 2000. They can be REST Server simply provides access to resources and a REST client accesses  and modifies the resources using HTTP protocol. Here each resource is identified by URIs/global IDs. REST uses various representation to represent a resource, for example, text, JSON, XML, but JSON is the most popular one.

Simple Microservices
Simple Microservices

In the past, typical monolithic applications were built using different layers, for example, a user interface (UI) layer, a business layer, and a persistence layer. A central idea of a Simple microservices architecture is to split functionalities into cohesive “verticals” not by technological layers, but by implementing a specific domain. The following figure depicts a reference microservices architecture program for a typical microservices application on AWS.

Basic HTTP methods

The following four HTTP methods are commonly used in REST based architecture.

  • GET – This is used to provide a read-only access to a resource.
  • PUT – This is used to create a new resource.
  • DELETE – This is used to remove a resource.
  • POST – This is used to update an existing resource or create a new resource.

Most of the time we will use the GET & POST only.

Features of Simple Microservices

  • It’s Includes so many concepts that it is challenging to define it precisely. However, all microservices architectures share some common characteristics, as the following figure illustrates
  • Decentralized – Microservices architectures program are distributed systems with decentralized data management. They don’t rely on a unifying schema in a central database. Each Simple microservice has its own view on data models. Microservices are also decentralized in the way they are developed, deployed, managed, and operated.

  • Independent – Different components in a microservices java architecture can be changed, upgraded, or replaced independently without affecting the functioning of other components. Similarly, the teams responsible for different microservices tutorial point are enabled to act independently from each other.
  • Do one thing well – Each microservice component is designed for a set of capabilities and focuses on a specific domain. Microservices development tools contribute so much code to a particular component of a service that the component reaches a certain level of complexity, then the service could be split into two or more services.
  • Polyglot – Microservices architectures don’t follow a “one size fits all” approach. Teams have the freedom to choose the best tool for their specific problems. As a consequence, microservices web containers architectures take a heterogeneous approach to operating systems, programming languages, data stores, and tools. This approach is called polyglot persistence and programming.
  • Black box – Individual microservice java components are designed as black boxes, that is, they hide the details of their complexity from other components. Any communication between services happens via well defined APIs to prevent implicit and hidden dependencies.
  • You build it; you run it – Typically, the team responsible for building a service is also responsible for operating and maintaining it in production. This principle is also known asDevOps. Microservices framework DevOps also can be helps bring developers into close contact with the actual users of their software and improves their understanding of the customers’ needs and expectations.

Create Simple RESTApi using PHP : 

<?php 
$response = new stdClass(); // object initialization
if(isset($_POST['action'])){ // verify the availability
 $response-> code = 200 ;
 $response-> message ="API triggered.";
}else{
 $response-> code = 400 ;
 $response-> message ="Action not found.";
}
echo json_encode($response);
?>




Likewise we can use $_GET[‘attribute’] and etc. with the single url we can provide multiple number of rest service and operations.

Create Simple RESTApi using Nodejs : 

var express = require('express');
var app = express();
var fs = require("fs");
app.get('/testapi', function (req, res) {
    return res.send({"Result":true});
})
var server = app.listen(5000, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
}) 

This is just an example rest service using nodejs. Nodejs is an light weight and very efficient platform to provide rest service.

programming

Leave a Reply

Your email address will not be published. Required fields are marked *