REST (Representational State Transfer) isn’t exactly a protocol, technically that's HTTP's domain only. It lives a layer above HTTP. REST is more like a data-interfacing style that works for well IoT. But since it’s based so heavily on top of HTTP, the two words are often used interchangeably.

REST is a well established standard for transmitting data, it is very internet friendly. If you’re online, just about every web service uses REST both internally and externally. Every modern computer & programming language has REST API (application program interface) support, so it’s very fast to get started, and if your device is going to talk to public ‘utilities’ like IFTTT, Facebook, Twitter, etc it will need to use REST.

Four Magic Words

There are four ways to move data around:

  1. GET (request data)
  2. PUT (send data)
  3. POST (create data)
  4. DELETE (natch)

Every web-browser uses these commands to get and put the data use use on the internet. And the data you get/put/post/delete is stored in ‘buckets’ called resources. The names of these buckets are also known as URLs - Universal Resource Location!

Restful URLs

So lets say you want to query the adafruit twitter account. You can go to the twitter.com server using http (http://www.twitter.com) and then request the adafruit resource (http://www.twitter.com/adafruit). This will give you a huge amount of data, but you can ‘drill down’ by adding more /’s and subcategories. So to read the post with our video visiting the NYC Formula E Series race go to https://twitter.com/adafruit/status/900750127425630208 - that big long number is a unique identifier for the tweet.

What makes it RESTful is that each / section gets more specific - the adafruit account, then the statuses, and finally the unique status #.

What your web browser gets when it goes to those URLs is a huge amount of HTML (Hyper Text Markup Language). You can see it by using View Source...

which looks like this (we pulled out just a section that shows a tweet)
<div class="js-tweet-text-container">
<p class="TweetTextSize TweetTextSize--normal js-tweet-text tweet-text" lang="en" data-aria-label-part="0">2017 is almost over, and we're celebrating another great year with a Circuit Playground Express sale! See <a href="https://t.co/lMXdvG9KLo" rel="nofollow noopener" dir="ltr" data-expanded-url="http://adafruit.com/sale" class="twitter-timeline-link" target="_blank" title="http://adafruit.com/sale" ><span class="tco-ellipsis"></span><span class="invisible">http://</span><span class="js-display-url">adafruit.com/sale</span><span class="invisible"></span><span class="tco-ellipsis"><span class="invisible"> </span></span></a> for deets

<a href="/hashtag/adafruit?src=hash" data-query-source="hashtag_click" class="twitter-hashtag pretty-link js-nav" dir="ltr" ><s>#</s><b>adafruit</b></a> <a href="/hashtag/adafruitsale?src=hash" data-query-source="hashtag_click" class="twitter-hashtag pretty-link js-nav" dir="ltr" ><s>#</s><b>adafruitsale</b></a> <a href="/hashtag/circuitplayground?src=hash" data-query-source="hashtag_click" class="twitter-hashtag pretty-link js-nav" dir="ltr" ><s>#</s><b>circuitplayground</b></a></p>
</div>

You can see the text of the tweet is embedded in there

2017 is almost over, and we're celebrating another great year with a Circuit Playground Express sale! See <a href="https://t.co/lMXdvG9KLo" rel="nofollow noopener" dir="ltr" data-expanded-url="http://adafruit.com/sale" class="twitter-timeline-link" target="_blank" title="http://adafruit.com/sale" ><span class="tco-ellipsis"></span><span class="invisible">http://</span><span class="js-display-url">adafruit.com/sale</span>

While you could, in theory, parse a webpage’s HTML via your device, its a hairy and unpleasant business that breaks very easily. So, instead, most services online provide a REST API which is simplified and machine-friendly. In those cases, the data is usually encoded with JSON or XML, rather than HTML, but still using HTTP.

Here are some examples of REST APIs:

Since we are using HTTP, the connection does not have ‘state’: the client connects to the REST API when needed, transferring data to/from the resource. When it’s done, it closes the connection.

On one hand, this is nice because you have a burst of data transmission, and then a disconnection so the server doesn’t need to hold the connection open. But the downside is you have to setup and tear-down the connection each time, and that can take up a ton of data.

This guide was first published on Dec 14, 2017. It was last updated on Mar 08, 2024.

This page (Take a REST) was last updated on Mar 08, 2024.

Text editor powered by tinymce.