4 ms·
It's "a beginner's guide" that starts with an explanation of what an API is and then jumps straight into PHP code with cURL! When someone just learnt what an A
by borplk 14y ago
It's "a beginner's guide" that starts with an explanation of what an API is and then jumps straight into PHP code with cURL!
When someone just learnt what an API is and doesn't have a clear idea of what it is or how it works an example code doesn't help at all.
When I'm asked to explain what APIs are these are the things I mention,
- an API is a fancy name for 'a way to talk to an external service'
- when you need to do something with an external service like Twitter you have to use their API to communicate with them
- an API is like a 'contract for communication' which specifies how to talk to the external party
- Most web APIs use the HTTP protocol as a way of communication to send messages back and forth and they also have a method of representing data, for example JSON or XML, that's just the same thing but a different way, using JSON or XML is like saying the same thing in English or Spanish, using the HTTP protocol or something else is like writing down a sentence vs shouting it out.
- When you use Twitter's API to unfollow someone, you don't know how exactly the unfollow happens, you don't have to know, all you know and have agreed with Twitter is that you ask Twitter to unfollow someone and they will do it, so in a way, using the API you are just sending them a 'signal' to do something. They can go ahead and change the inner workings of that API and as long as the part that is exposed to you remains the same you don't care because as far as you are concerned it does the same thing even though it may be doing it in a very different way
Here's a trivial example of a real-world API,
Imagine you run a restaurant and you need to buy fresh supplies to cook your delicious dishes every day.
You hire someone and teach them to buy the supplies as you order. You trust them to buy good quality stuff and deliver them to you.
You agree to give them order instructions via SMS. And you agree on the following format:
BUY
15 Salmon Fish
20 Avocados
DELIVER BEFORE 30 January 2013 14:00
END
Now the person you have hired can use your 'Order API' to work with you. You send them a message in a format that you have agreed upon and using a medium that you have agreed (SMS).
Hope that helps some beginner who is struggling with all the fancy terms being thrown around without explaining the principals and the simple details that everyone takes for granted once they have passed the initial learning phase.