Tag: optimumbrew

Understanding of Web Service & REST API

What is API?

API (Application Programming Interface) is a particular set of rules (‘code’) and specifications that software programs can follow to communicate with each other. For example, you have a hardware button on your TV which turns it ON/OFF. Now suppose you want to turn ON the TV from a distance. You just press the ON/OFF button on a remote control and the TV set action on the command given by the remote control. This is how API works! Think of TV as a software program having services and resources, and the TV Remote control as another software program which use these resources. The method (or radio/infra red waves) through which a remote control communicates with a TV set is an API.

When and where it is used?

It’s used when 2 or more separate application need to work together to achieve something they can’t do alone.When interaction involve sending data over network, at that moment Web Service comes into the picture.

What is Web Service?

As the word sounds, they are not new fundamental business concept, it just a technology which permits old business concept to work together over the internet using some protocol. i.e. Oxford Dictionary API, in which you will send word, and in return it gives meaning of that word.

In simple way Web Service is nothing but a message passing (In XML & JSON format) between two machines. A client sends request over the Internet and a server receives that request, processes it and returns a response. When a browser makes a request for a webpage, it receives HTML and other related content in the response. But when it just asks for data and uses JavaScript or other client-side code to process the response, a web service has been used.

Modern web service communications are nearly always handled over HTTP. But the format of the message that are being sent and received can be different. Let’s consider one scenario for more understanding,

One service provider (A) is building application which shows latest designer clothes like amazon. For that he need to set up database to add products information (maybe it’s price, product name, images etc.) and one program to get that resources and display on application(Android, iOS, Web client) which is called as API call.

11
            Fig 1. Understanding of web service

 

Note: Mark that this is limited to his application only, this will not allow other application to access his local data.

Read More

JSON Web Token

There are basically two different ways of implementing server side authentication for apps with a front end and an API:

Session Based System

In session based system like social networking system, e-commerce system or net banking system, the user data are stored on server side in a text file in temporary directory when user logged into the system which is called session data. The server generates the unique session ID for each user’s session data and send back to the user.

User can store that Session ID in cookies so that it can be used for further communications. When user requests for particular data after login, user has to send the session ID with each request from the cookie, so server can authenticate the user. And according to that session ID, server gives response to that user.

Session based system is STATEful as the server has to store the session for each user at server side and also user has to store session id in cookies. So if there are number of users then it is very difficult to maintain scalability and performance of the system and it will use extensive memory.

To overcome this scenario, token based system comes into the pictures.

Token Based System

Token based system is stateless, means no user data are stored on the server side, only user has to store token at client side which improves the performance and scalability of the system. When user sends the subsequent request after login, user has to provide token to the server. And from the token, server identify the user and give response to user.

Read More

Getting Started with Caching in PHP using memcached

Caching is used to store the data which are frequently used. The main advantage of caching is that it increases the performance of the site or an application by decreasing the load on to the server like database.

There are different caching methods to cache the data like caching content in file, memory or database. Memcached is one type of memory caching system. It is very useful when large number of data you want to cache.

It is distributed memory caching system. Memcached is key-value store for caching small chunks of data from result of database, API or page rendering. Basically it can cache anything if you can turn it into key => value. Memcached solves many problems related to large data caching.

Memcached is better because of the following reasons:

  1. It’s REALLY fast – Everything’s in memory, and it’s highly optimized for situations just like yours (and caching in general )
  2. It’s distributed – This means that if you have multiple web / app servers running, they can all access the same cache
  3. You can pool multiple servers for memcached – If you’ve got a few servers that are relatively underutilized (or several dedicated cache servers), you can pool them all together into one big cache
  4. It’s super-scalable (for the reasons mentioned prior)
  5. It’s got great PHP support – The PECL package for memcached was recently updated with a lot of new goodness
  6. You can even store your user sessions in memcached – just set it up in your php.ini file. This is much faster than storing sessions in databases, and allows your sessions to persist across multiple web hosts (if you’re in a load balanced situation). This will also give your site a bit of a performance boost as there’s no need to hit the file system / database for session info on every request.

What memcached does?

Read More