REST Architecture

In this tutorial I will tell you about REST architecture, The most popular architectural Style for creating web services.

REST is stands for "Representational State Transfer" is not a technology that we can buy or a library that we can use in our project.

The ideas and term we use to describe "RESTful" systems were introduced and collated in Dr. Roy Fielding's thesis, "Architectural Styles and the design of Network-based Software Architecture". This Document is academic and uses formal language, but remains accessible and provide the basis for the practice.

The response of Rest full service of any kind like XML, JSON, text., or any other format.


SOAP web services define a protocol, a service is call SOAP only if all the specification define by protocol is followed by the service.

Unlike  REST SOAP response can be only XML format.

SOAP defines standards to be strictly followed.

SOAP requires more bandwidth and resource than REST.

Basic design principles followed by rest

1. Use HTTP method explicitly
2. Be stateless
3. Expose Directory structure-like URIs
4. Transfer XML, JSON or both.

Use HTTP method explicitly

This is one of the key characteristic of RESTful service, a way that follows the protocol as defined by RFC 2616. Below we are defining some HTTP method define in the RFC 2616.

If you want to more on detail you can follow the RFC document.

There are four main HTTP verbs or methods used by well designed RESTful systems.

The basic REST design principle establishes a one-to-one mapping between create, read, update and delete (CRUD) operations and HTTP method

1. GET (read)
2. POST (create)
3. PUT (update)
4. DELETE (delete)


In REST  style GET HTTP request is used for transferring  the representation of named resources from a server to a client.

The main key point in REST is that the GET should only used for accessing the resource from server, it should not modify anything on the server side.

GET is called a safe request because it does not changes the state of the server. The safety of a get request allow it to be cached.

GET request is also intended to be  idempotent. This means that issuing a request more than once will have no consequence.


The POST request should be used when the client cannot predict the identity of the resource it is to be created.

suppose we are registering a user, in this case we have no idea how the server will name these resources.

 After the successful POST request the server will return a 201 HTTP response code with a Location header indicating the location of newly created resource.

POST is neither safe and nor idempotent.


The  PUT request is used for updating an existing resource in server.

PUT is safe and idempotent.


The DELETE request is used for removing a resource form server

There are other verbs that are not widely use but provide value.


The head request is used to issue a request for a resource without actually retrieving it. It is a way for a client to check for the existence of a resource.


The OPTIONS verb is used for interrogate a server about a resource by asking what other verbs are applicable to the resources.


Each of a client’s requests contains all application states necessary to understand that re-quest. None of this information is kept on the server, and none of it is implied by previous requests.

Every request is handled in isolation and evaluated against the cur-rent resource state.

URL Structure for REST web services

The URL of REST web services should be Resource based URI.

everything in the server in which user is interested should be represented as 

For example in facebook messenger, POST, Messages, Profile and Comments are all resources

1. Noun not Verb : Use Noun in place of Verb in URI.

Example      [Right] 

2. Plural not Singular : Resource name must plural not singular.

Example [Right]

Resource relations

one resource can depend on other resources

CASE : one to many relation

Example message and comments,  each message have multiple comments

for example message1 have comment1 with id 1, comment2 with id 2
                  message2 have comment1 with id 1, comment2 with id2

then how to make URI that represents the relation between message and comments

Here the URI syntax{messageId}/comments/{commentId} 

Example  # message1 with comment2
        # message2 with comment1

Important HTTP codes for Rest web services

Manage users in MySQL server

This is the advanced user tutorial for MySQL server,  also known as MySQL Administration tutorial.
In this tutorial I will explain you how to manage user in MySQL.

Managing user means creating, deleting, assigning permission, revoking permission/privilege,

before going to detail I recommend you, to first see the structure of user table under mysql database

just open your mysql client and type

use mysql;

desc user;

here we showing some field of user data base

Now we have to understand the two terms define below, more of us already know these terms.

Authentication : Means system know about you (user). system have some kind of information about you.

MySQL uses username, password and hostname or host-ip for authentication of user

Autherization : Permission to do any operation using your authentication detail.

Add a new user in MySQL server

use the following sql command for adding new user to your MySQL server
CREATE USER 'ganga'@'localhost' IDENTIFIED BY 'password';
you need administrative privileges for this.

This command will create a user ganga and password is password.

This command simply create a user without any permission. you can do nothing.

if you login to MySQL using this credentials(ganga, password) you only see information_schema database, all other databases hidden to you.

Now we provide privilages/permission to newly created user ganga.

Some privileges are database level and some are table level.
below is the table contains some MySQL privileges

List of privileges

Assigning privileges to a User

GRANT privilege1, privilege2, privilege ON database_name.*  TO ‘username’@’host’ IDENTIFIED BY ‘password’;

GRANT select ON college.*  to 'ganga'@'localhost' identified by 'password';

The following command provide select permission to user ganga in college database.

Deleting a User  

To delete a user permanently use the following command 

mysql>DROP USER ‘ganga’@’localhost’;

Removing all user privilege

To remove all user permisson use the following command-

mysql>REVOKE ALL PRIVILEGES FROM ‘ganga’@’localhost’;

Changing user password

To change the password use the following command --

mysql>SET PASSWORD FOR ‘ganga’@’localhost’ = PASSWORD(‘newpassword’);

Renaming user

To rename the user use the following command --
mysql>RENAME USER ‘ganga’@’’ TO ‘jamuna’@’localhost’;

Revoking privileges 

mysql>REVOKE DELETE, UPDATE FROM ‘ganga’@’localhost’;

MySQL backup and restore

As we know that MySQL store the data. Data is important for any organization.
since there may be chance when our MySQL server crashes or the machine in which MySQL installed will crash.

If it would  happen we lost the data. So we must backup our data regularly.

MySql client provides different utility to backup the data and restore this backup data to new MySQL server.

There are different technique and modes for creating and restoring the backup. we are not going to see all techniques this time.

Here we are using mysqldump client utility that is provided by MySQL to create and restore the data.

the mysqlump utility is uses for creating logical-backup (means the sql statement that we used to create the database and table like insert, create) that necessary sql staements that is used to restore the database again

Syntax for using mysqldump


Case 1. shell> mysqldump [options] db_name [tablesname...] > filename.sql

Case 2. shell> mysqldump [options] --databases db_name > db.sql

Case 3. shell> mysqldump [options] --all-databases >dbs.sql

These are the three ways given above to take backup of MySQL server.

In Case 1 we can take the backup of data base as a set of particular tables, means we can take  backup of particular tables.

In Case 2 we can take the complete backup of one or more database.

In Case 3 we can take the complete backup of all database in the MySQL server.

Now we take an example to understand all the above syntax for taking  data base backup.

Case 1  suppose we have a "college databse" that contains a table called student and we want to take backup this table only

shell >  mysqldump -u {username} -p college student >student.sql //enter

suppose now we want to take full backup of the college databse

shell >  mysqldump -u {username} -p college >college.sql

Case2 suppose we have 3 database in our server college, shop, rent
and we want to take the back up of shop and rent

shell >  mysqldump -u {username} -p --databases shop rent  > shop-rent.sql

Case 3 we want to backup all the database
shell > mysqldump -u {username} -p --all-databases   > all_db.sql

Restore backup data to MySQL

In this section I will tell you how to restore backup data that we have created using mysqldump client.

Here we are consider some real-time scenario to store the data.

case 1. You only backup a table instead of whole database and you want to restore this table on other machine for this use the following command

mysql -u username -p database_name < table_backup.sql

case 2. Suppose you have created the backup of full database in this case if you use --databases  (as in case 2 in backup section) to take  backup then backup file contain the create database statement and use database statement you don't need to create a database  and use the following command

mysql -u username  -p  < database_backup.sql

otherwise before exporting backup  you have to create the database and then you use the following command

mysql -u username -p database_name < database_backup.sql

Data Type for MySQL

This tutorial will tell you about data type which is used in MySQL server. The version of MySQL which I used to write this tutorial is  5.7.15. So there might be some chance that some of the data type not supported in your MySQL version.

So first thing is that what is Data type ?

In general as we know that there are some number and characters.
Number represent the some values and values further can be divided into categories like integer, real.

In computer science there must be some equivalent representation to represent these values in computer or in a program. so every computer language have its equivalent representation to repreasent these number.

so now we look into MySQL data type.

we can categorized the MySQL data type -

1. Numeric Data Type
2. Date and Time Data Type
3. String (characters and bytes) Data Type
4. Spatial Data Type

Numeric Data Type :


This data type is used for storing the number value.
This can be further categorized-


size : A 1-byte integer. 
range : signed integer is -128 to 127 and for un-signed is 0 to 255.


size : A 2-byte integer.
range : signed integer is -32,768 to 32,767 and for un-signed is 0 to 65,535.


size : A 3-byte integer.
range : for this signed integer is -8,388,608 to 8,388,607 and for un-signed is 0 to 16,777,215.


size : A 4-byte integer.
range : signed integer is -2,147,483,648 to  -2,147,483,647 and for un-signed is 0 to 4,294,967,295.


size : A 4-byte integer.
range : for this signed integer is -9,223,372,036,854,775,808 to
 9,223,372,036,854,775,807  and for un-signed is 0 to 18,446,744,073,709,551,615


A fixed point number (M,D).

M is the maximum number of digits is 65 and default 10
D is the maximum number of decimal points is 30  and default 0


A small floating-point-number




A double precision floating-point-number.




A bit  data type is used to store bit-field value field Type (M), storing M of bits per value. default is 1 and maximum 64


Like tinyint , a value zero considered as false and non-zero considered as true 

Date and Time Data Type



format : YYYY-MM-DD
size: 3 bytes storage required
range : '1000-01-01' to '9999-12-31'


format : YYYY-MM-DD HH:MI:SS
size : 8 bytes storage required 
range : '1000-01-01 00:00:00' to '9999-12-31 23:59:59'


format : YYYY-MM-DD HH:MI:SS 
size : 4 bytes storage required
range : '1970-01-01 00:00:00' to mid-year 2037


format : YYYY or YY 
size : 1 byte storage required
range : 1901 to 2155 (for YEAR(4)), 1970 to 2069 (for YEAR(2))

MySQL begineer tutorial part-3

Hello Friends,

This  is the third series of MySQL beginner tutorial. I hope this third tutorial will enhance your knowledge of SQL with MySQL databse.

In previous two tutorial (tutorial-1 and tutorial-2) we learn how to connect to MySQL server and creation of data base and table.

we are using college database for our tutorial. In this part we learn some more SQL statements.

SQL statements and clause which we learn in this tutorial are-

INSERT statement
SELECT with LIMIT clause
Conditional SELECT using WHERE clause
WHERE clause with AND, OR, NOT conditional operator

I hope this will add some new knowledge about SQL statement

INSERT statement : 


INSERT statement is used for populating the table, or we can say that INSERT statement is used for creating a record or tuple in table.

Since we have college database and student table, so we insert a student detail in our student table.

syntax for INSERT statement

INSERT INTO tablename (columnname 1, column2name2,.....) VALUES (columnvalue1,columnvakue2,...)

 Now in student table--

mysql>INSERT INTO tablename (roll_no, name, sex, age) VALUES ('101', 'RAM', 'M', 24);
mysql>INSERT INTO tablename (roll_no, name, sex, age) VALUES ('102', 'Neha', 'F', 22);

so now we have successfully insert two rows in student table.

NOTE : here one thing is for notice , that in values for roll_no, name., and sex we use single quotes ('') to put the value and for age we did not use qoutes since when we creating we define roll_no, name, as varchar and sex as char datatype and for age we define int datatype so when we insert a value for char or varchar datatype we use '' and for number in this case int we does not use ''.

you can check the datatypes of column for student table using DESC commnd that I have already told you.

SELECT statement :

SELECT statement is used for viewing the data of a particular table, so now we see the data of student table

syntax for SELECT statement

SELECT column[s] FROM table-name.
mysql > SELECT roll_no, name, sex, age FROM student;

selecting the particular column
SELECT roll_no FROM student;

selecting all column using *
mysql > SELECT * FROM student;

SELECT with LIMIT clause---------------

suppose we have table that contains 100s of record and we want to show only top 2 results, in this case we uses LIMIT clause to limit no of records

SELECT roll_no, name FROM student LIMIT 2; // this will return only first 10 record of the table.

WHERE clause in SELECT statement

WHERE clause is used for filtering the result of select statement.

suppose we want to select the recode which match to a particular condition

SELECT sex, age from student WHERE name='Akriti'.

SELECT roll_no, name from student where sex ='F'

WHERE clause with AND, OR, NOT conditional operator

I hope this third tutorial will help you to gain some knowledge about SQL and using it with MySQL.

If you have any confusion or suggestion you can type your query and suggestion in comment section and I will like to solve your query.

So we meet next time with next series of this tutorial.

MySQL beginner tutorial part-2


In the previous tutorial we just know about some basic concept about MySQL and some basic SQL commands.

In this tutorial I will tell you about some new  SQL (Structured Query Language) statements .

USE statement


This command is used for changing or selecting  the database from a list of databases.


when we use show databases; statement, it list  all available databases for a user.

so for selecting a particular database for working we use USE statement.

Syntax for use-

mysql> use db;         // replace db to your database name

As we know  RDBMS  uses table to represent data. so in RDBMS database contain a collection of tables.

Table is like a matrix contains rows and columns.

rows also knows a tuple or record

Here is an example of how a tables look like in MySQL.

student table

you can see an example of table named student where roll_no, name, sex, age are column name.

(101, Ram, M, 24) is a row of student table also known as tuples or record

CREATE statement in MySQL


Create a database 


In this section we learn about how to create a database in MySQL.

To create a database in MySQL we uses CREATE statement-

Suppose we are going to crate a database name college which store the student detail

mysql > CREATE DATABASE college;

it will create a college database in your MySQL server.
you can check it using SHOW DATABASES; statement

Create a table in database

In this section we learn about how to create a table in MySQL.

To create a table in MySQL we uses CREATE statement-

Step 1- First select the database (USE statemnt) in which you want to create a database.

In our case  we use college  as database that we just created.

USE college;
Step 2- Now we create a table student-

query to create a tabale-

mysql> CREATE TABLE student(roll_no varchar(20), name varchar(20), sex char(1), age int(3));
this command will create a table called student, which roll_no, name, sex, age as column name

DESC statement


DESC statement is used  to show the structure of a table 

query to see the structre of table-

mysql> DESC student;;

student table structure

MySQL beginner tutorial


I am writing this basic MySQL tutorial to provides some basic hands on to the student  and developers. My aim to writing this tutorial to provide some basic and quick learning of Data Base Management System(DBMS).

Firstly I will tell you about MySQL.

What is MySQL?

MySQL is an Relational Data Base Management System (DBMS) which is used to store and manage the application data.
MySQL works as Data Base server, its mean MySQL is a server application.

Now I am going to Explains some terminology that will clear your concept.

What is Data ?

Data is just fact that can be gathered and stored and have implicit meaning.
like Name of students is a data.

What is DataBase ?

Data Base is something in which we store data, means provide some base to store data.
like File can be some form of data base to store the students Name.

What is DBMS ?

DBMS is a collection of program that helps to create database and manage it efficiently.

First thing which you need to play with MySQL server, is installing the MySQL in your system.

The link given below provides you steps to install MySQL server in Linux/ubuntu.

Install MySQL in ubuntu

After installing MySQL successfully, the first thing which you need is MySQL client.

since I am already tell you that MySQL is a server, so to use it you required some client porgram that can connect you to MySQL server.

There are many MySQL client programs, some are GUI based and some are command based client.

I advised you if you are a newbie use command line MySQL client because if you use GUI based client initially some concept may not be clear.

When you installed MySQL server is come up with MySQL client program also. So there is no need to install MySQL client.

I hope , you  have successfully installed MySQL sever and MySQL client program to your machine.

If you have any problem during installation you can type your problem in comment section.

So Now you have successfully installed MySQL programs, server and client both.

Now we see how to connect with MySQl server using MySQL client-

Step 1. Jsut open your Linux terminal

Step 2. write the following command to connect the MySQL server from your client

mysql -u username -p  [enter key] // replace username string to your user name
Enter password:  // provide your password

 If every thing goes successfully you can connect to MySQL server.

when we install MySQL server its come with some its own data base which it uses internally, so just play with MySQL

Type the following command

SHOW databases;    // this command list all the data bases in MySQL

you look something like this ---

mysql> show databases; +----------------------------------+
| Database                    |
| information_schema   |
| mysql                          |
| performance_schema |
| phpmyadmin               |
| sys                               |
| test                              |
8 rows in set (0.00 sec)
congrats ! now successfully run your first command.

In next tutorial I will provide you some basic command.

Install MySQL on Ubuntu


In this tutorial I will show you steps to install MySql server.

Step 1 : Update your system

Type the command given below to update your system

sudo apt-get update
sudo apt-get upgrade

Step 2: Install MySQL

Type the following command to install MySQL 

sudo apt-get install mysql-server

During installation process you get a window given below that asks you to provide password for your root user. read the instruction carefully. 

mysql installation window

After installation succesfully type the following command to check weather MySQL  server is ruuning or not.

nmap localhost

Starting Nmap 7.01 ( ) at 2016-08-26 17:48 IST
Nmap scan report for localhost (
Host is up (0.000090s latency).
Not shown: 995 closed ports
22/tcp   open  ssh
80/tcp   open  http
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
3306/tcp open  mysql  

by default MySQl uses 3306 port to run the server

if you get the highlited portion it show your mysql server is successfully installed and ready to use.

Spatial Data Type in MySQL DataBase

Hello friends,

In this tutorial I will be able to provide you some information about Spatial Data and Spatial Data Type in MySQL.

What is Spatial Data ?

Spatial data also known as geospatial data, represents the location, size and shape of an object on  Earth such as a minar, lake, mountain or temple.
this data can used to locate any device, mountain and place globally.

Spatial data consists of point, line, polygon and many others geometric object.

Spatial Data Types In MySQL

MySQL (here we use the version 5.7) has data types that correspond to OpenGIS classes. Some object that store single geometry values:

  •     GEOMETRY

  •     POINT


  •     POLYGON

GEOMETRY  can store geometry values of any type.

POINT, LINESTRING and POLYGON restrict their values to a particular geometry type.

data types that can hold multiple values:





MySQL supported spatial Data Format

Two  types of format are supported by mysql queries-

   1.  WKT (well known text) format
   2.  WKB (well known binary) format


The Well-Known Text (WKT) format of geometry values is designed for exchanging geometry data in ASCII form

Example of representing a point in WKT format


The Well-Known Binary (WKB) format of geometric values is used for exchanging geometry data as binary streams described by BLOB (Binary Large Object) values containing geometric WKB information.

WKB uses 1-byte unsigned integers, 4-byte unsigned integers, and 8-byte double-precision numbers (IEEE 754 format). A byte is eight bits.

For example, a WKB value that corresponds to POINT(1 1) consists of this sequence of 21 bytes, each described by two hex digits:


The sequence consists of these components:

Byte order:   01
WKB type:     01000000
X coordinate: 000000000000F03F
Y coordinate: 000000000000F03F

Storing geolocation of a point in MySQL using Spatial Data Type

Reference :

Storing geolocation of a point in MySQL using Spatial Data Type

AS we  know todays developing location-based application is most common.
we know, we can get the location of a point in earth using Latitude and Longitude. we can uniquely define any point in a Earth using latitude and longitude, together they used to defined geographical co-ordinate of Earth's and represent the angular distance of any location from the center of the Earth.

The best way of storing latitude and longitude or position of a point in MySQL is  POINT class of MySQL Spatial Data Types.

When using POINT class, the order of the arguments for storing co-ordinates must be POINT(longitude, latitude).

For example suppose geo-location of a point is -

 long = 77.18563599999993       // long represents longitude
 lat    =    28.513096                   // lat represent latitude

Step to store and retrieve these points in MySQL

Step 1 : first we create a table for storing location of a point using POINT class of  Spatial Data Type.

-- Table structure for table `site`

        CREATE TABLE `site` (
             `id` tinyint(4) NOT NULL,
              `position` point NOT NULL)

Step 2 : SQL syntax for storing geolocation using Spatial-

      INSERT INTO `site` (`id`, `location`) VALUES ('1', GeomFromText('POINT(77.18563599999993 28.513096)'));

This sql commands store the location of a  point as binary GEOMETRY object.
GeomFromText(), this function return the geometry object.

Step 3 : Retrieve points from table
         SELECT *, AsText(position) FROM site

How to know a particular Font is Availabele or not on ubuntu

Hello Friends.

Sometime we have to know weather a particular Font is Available or not on
Ubuntu machine.
fc-list command line tool is used for knowing the installed font on machine.

Suppose we want to know weather Arial font is Available or not, to know it just type the following command

fc-list | grep Arial

Domain Name in computer network

As we know that everywhere there is network of computer/devices connected through internet. when we talk about computer network there is a need to identify a computer uniquely. To identify a computer uniquely in a network a concept was arise known as IP (Internet Protocol address) address, Similar to as we have an unique House address.

The IP address is like ''. But these number is not easy to remember. So a concept arise that provide mapping of these IP address to a unique name. As we know from our college life to remember a string of character is always easy to remember  a long string of number.
So the name which we assign to a IP addrees is known as Domain name.

For example is the mapping of IP address ''

where techie-knowledge is the domain name 

But computer network  operate on IP address so there is  a service required known as DNS(Domain Name System)  server that translate domain name into IP address.