Wednesday, June 14, 2017

REST API for Dummies: The Store Metaphor

From: https://medium.com/@sheetsu.com/rest-api-for-dummies-the-store-metaphor-c9e531bcd425
This is the ultimate REST API for Dummies. In order to be able to give you a REST API definition, let’s go shopping. I will use what I call “The Store Metaphor”. This way you will also be able to understand what the hell is Sheetsu as well and how it can help developers out there to keep the quality in their beautiful code while coding less. This is not a REST API tutorial but a simple explanation for people like me who is not a developer but for some crazy reason feels entitled to understanding this mystery. If you code for a living and have always wanted to share your passion with your mom/dad or your girlfriend/boyfriend but was never able to explain it to her, to find the words and the examples they could relate to, this post may be the link. ;)

This post will cover:
  • What is REST API?
  • REST API: The Store Metaphor
  • REST API & Google Spreadsheet
  • REST API & API: The Difference

What is REST API?

What the hell is a REST API or Restful API? If you are like me, you are thinking the same thing:
  • I am not an albino living in a cave (so, not a developer)
  • I have no intention in start developing or coding
  • All I see below in this image are the cute colors (green matches red, who knew?):
Cute colors some people call code and make money out of it
To sum up, I don’t have time to get into details to create a solution, I just want a solution that is ready for me — that’s it!

But I still consider myself pretty smart and I want to understand at least the basics, right? So first, I go ask the developers I work with @ Sheetsu about the meaning of a REST API:
“ C’mon Nani, it’s so obvious. It’s a programming architectural implementation intended to increase the efficiency of communication in computing systems by making that data available on-demand by sharing references instead of the complete copy of the data itself. ”
Was that even English?

So then I tried to get more info with specific communities, like the awesome guys at Hacker News and Quora but I still was not getting it. So I try to shake it off and go to uncle Google, looking for an answer a normal human being can understand. Google tells me:
“REST stands for REpresentational State Transfer”
“API means Application Programming Interface”
That moment you have no idea what is happening to your life
Well, I did learn something from it all… that maybe I am not as smart as I thought.
But I will not give up!! Steve Jobs fought cancer for years, my poor mother survived 80’s fashion and Britney Spears still has a career after a shaved head, so anything is possible in this world, right?

Let’s say you go to your favorite store to buy a new pair of jeans.
You look around and find exactly what you were looking for! But in the wrong size: It’s small while you need medium. But, unless you are a shop lifter, you do not have access to that mysterious room in the back of the store that holds all items they sell, at all sizes and colors.
To get access to this wonderland, you need to make a request to the sales person so you receive back exactly what you need: those pair of jeans you loved, but the right size for you.
You need to make a request to the sales person that has access to that mysterious room in the back of the store
Since the sales person has this special access, he goes inside, gets exactly what you need, comes back and delivers what you requested.
Yes! It’s done!

So let’s Review

In this metaphor, the sales person is the messenger, right? It took a request you made, used the access he had in order to give you what you wanted or at least worked to give you the answer to your question.
Now get ready for this: the sales person is the API!!
Whaaat? Yes!
An API is the messenger that takes a request, tells a system what you want to do and then returns the response back to you!
It looks something like this:
An API is the messenger that takes a request, tells a system what you want to do and then returns the response back
… Did I just blow your mind? Let’s get a big deeper than…

REST API & Google Spreadsheet

This is simply the best real-time update you can imagine! Let me explain by going back to the metaphor: let’s say I gained a few pounds.
I tried the pants, size medium, but they didn’t fit. This is our worst nightmare, right? Not only I will have to stop eating chocolate for a while but worst: I will have to find the sales person again!

You guys know what I am talking about. Every single time you look for that freakin’ sales person, they are nowhere to be found! It’s like they disappeared into a dark whole! Then, we always have to stop pause our plans to start a saga to find someone that can help.

At this stage you just want to get the right pants size, pay and leave the store to move on with your life and not waste any more time!
Oh… it would be amazing if we could just type what we needed and the pants you were holding in your hands would magically become your size!
Now let me blow your mind again: THAT IS WHAT SHEETSU DOES!!
mind = blown

Sheetsu: How does it work?

Sheetsu allows you to create a REST API from a Google Spreadsheet. Let’s say it in a different way: Sheetsu turns your Google Spreadsheet into a REST API. Ok, let’s try one more time: Sheetsu connects whatever data you need to a simple Google Spreadsheet in a few steps:
1 . Open a Google Spreadsheet and copy the link
2 . Paste it into Sheetsu
3 . Get your REST API link!

Let me give you an example:

If you use this Sheetsu REST API link to build a website, every time you change something in your spreadsheet, it will automatically change the content on your website too, in real-time! We have “caching” which is a fancy way of saying we will make sure it will all happen fast ;)
It looks a bit like this:
Sheetsu turns your Google Spreadsheet into a REST API

REST API & API: The Difference

Well, to be fair to you, I explained what is an API. So if you ever asks a developer to show you an API or a REST API, that’s all you will see: links. REST is the way you organize these links.

In case you want to find out more about it, I will write a post so you can understand how developers process the same information I gave you on this post. But be careful not to send too many requests because once you get into a black whole… You know what they say…
You may finally find that freaking sales person you were looking for.
When the sales guy shows up last minute for the commission
Well, I hope I was able to truly help you! In case you want to try Sheetsu now, it’s FREE and you can signup using your Google account. If you still have questions, please send me an e-mail to nani@sheetsu.com and I will do an awesome research and write about it ;)

Tuesday, November 24, 2015

REST vs RPC

This is taken from: http://apihandyman.io/do-you-really-know-why-you-prefer-rest-over-rpc/
And the author has done a simple and fair evaluation of the two.

Conclusion:

ITEMWHO WINS?
BeautyDraw
DesignabilityDraw
API definition languageDraw
Predictability and semanticREST
HypermediabilityDraw
CachabilityDraw
UsabilityDraw

Do REST really wins?

REST wins thanks to the predictability and semantic item.
So, is the resource approach better than the operation one?
No.
RPC and REST are only different approaches with pros and cons and both are valueabledepending on the context. You can even mix these two approaches in a single API.
The context, that’s the key. There are no panacea solution, don’t follow fashion blindly, you always have to think within a context and must be pragmatic when choosing a solution.
At least, I know now why I like the resource approach: its predictability and the frame given by the full use of HTTP protocol. What about you?
One last word to leave you with food for thought: in this time of advent of functionnal programming, having operation request style could make sense…

Idempotent Methods - PUT, DELETE, and safe request methods

Idempotent Methods and understanding their behavior is critical to getting REST right and nothing explains it better than reading the spec about what it means.

4.2.2. Idempotent Methods
   A request method is considered "idempotent" if the intended effect on
   the server of multiple identical requests with that method is the
   same as the effect for a single such request.  Of the request methods
   defined by this specification, PUT, DELETE, and safe request methods
   are idempotent.


http://tools.ietf.org/html/rfc7231#section-4.2.2

Wednesday, September 30, 2015

A quick list of Hypermedia for REST Articles

Hyper-Media APIs by @jvelilla on @scoopit
http://sco.lt/8OlOwT

Will try and bring in the articles curated by @jvelilla here.

Sunday, September 27, 2015

When is Your API NOT RESTful?

Five Clues That Your API isn't RESTful

  • It has a single endpoint

  • All requests are POSTs
  • Response metadata is in the body, not header
  • There are verbs in the URL
  • The URL includes method names
  • Do We Care About RESTfulness?

Saturday, September 26, 2015

What does REST really mean?

https://standardout.wordpress.com/2012/04/14/what-does-rest-really-mean/

ReSTful web services have been popular for some time, yet still today there is confusion about what it means.  Some will say it is a web service that doesn’t use SOAP standards, others will argue it has to do with using HTTP’s PUT and DELETE methods along with their more popular siblings GET and POST, and still others will argue it has to do with an even more confusing acronym HATEOAS.  Everyone seems to have an opinion on what it means, and the only thing that is clear is that they are talking about different things.  Which is fairly ironic considering the term is an acronym for a pretty clear idea and its spelled out fairly clearly in Roy Fielding’s paper.

Wednesday, September 23, 2015

HOW TO DESIGN GREAT APIS WITH API-FIRST DESIGN AND RAML



With the spread of open source, we are witnessing the building of an API economy that is based on the principle of developer-first--putting your target developers’ interests ahead of all other considerations when setting out to design a great API. By building on top of APIs that are designed with the developers’ interests at heart, you are able to save you and your developers a lot of work while laying down the building blocks for others to build on top of.