REST Services

Understanding REST architecture and implementation in modern web applications

What is REST?

REST (REpresentational State Transfer) is an architecture principle where web services are viewed as resources uniquely identified by URLs. The key characteristic of RESTful Web services is the explicit use of HTTP methods to denote different operations.

REST functions can be distributed across multiple servers or data centers, making them ideal for modern cloud architectures.

HTTP Methods in REST

POST

Create a resource

GET

Retrieve a resource

PUT

Update a resource

DELETE

Delete a resource

Arduino IoT Example

Let's explore a practical example using Arduino with GPS tracking capabilities. This example demonstrates how to implement REST services in an IoT context.

Sample REST URL:
http://www.test.org/Georeference.aspx?SOURCE=74KM&TIME=00:11:36&DATE=04/01/01&LATITUDE=1233.715480&LONGITUDE=4155.726918
Required Arduino Capabilities:
  • Internet connectivity
  • GPS module initialization
  • GPS coordinates retrieval
  • String formatting
  • URL calling capability

Implementation Example

Here's a sample implementation of the georeference handler:


//GeoReferences.aspx
//Author: Vittorio Margherita
//Version 4.51
public partial class WebForm1 : System.Web.UI.Page
{
    string ArduSource;
    string ArduTime;
    string ArduDate;
    string ArduLatitude;
    string ArduLongitude;
    bool QueryMissedParam;

    protected void Page_Load(object sender, EventArgs e)
    {
        XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8);
        DateTime TimeOfTheDay, DayOfTheDate;
        GeoReference GeoString = new GeoReference();
        DatabaseConnectionDataContext db = new DatabaseConnectionDataContext();
                    
        ArduSource = Request.QueryString["SOURCE"];
        ArduTime = Request.QueryString["TIME"];
        ArduDate = Request.QueryString["DATE"];
        ArduLatitude = Request.QueryString["LATITUDE"];
        ArduLongitude = Request.QueryString["LONGITUDE"];

        //check if the current App is authorised to work
        var query =
        from righe in db.AllowedPCCs
        where
        (righe.PCC == ArduSource)
        
        select righe;