What is an API
Elliott Richmond
What is an API?
•An API defines functionalities that are
independent of their respective
implementations
…
•an application programming interface
(API) is a set of routines, protocols,
and tools for building software
applications.
…
•An API expresses a software
component in terms of its operations,
inputs, outputs, and underlying types.
…
•a set of functions and procedures
that allow the creation of applications
which access the features or data of
an operating system, application, or
other service.
What we know
•Application Programming Interface.
•An API is a software intermediary
that allows two applications to talk to
each other.
API
In other words…
•an API is the messenger that delivers
your request to the provider that
you're requesting it from and then
delivers the response back to you.
JSON
JavaScript Object Notation
json
json
Request
ProviderAPI
Response
API Providers
API Glossary
•Endpoint Requests
GET / POST / PATCH / DELETE / …
API Endpoints
https://api.domain.com/oauth2/token
https://api.domain.com?access_token=xxxxxxx
https://api.domain.com/rest/?api_key=xxx&name=bob
API Request Code
•HTTP
•cURL
•Javascript (AJAX, XMLHttpRequest)
•PHP cURL
API Request Code
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => “https://api.domain.com/?param&param&param…..“,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "grant_type=client_credentials",
CURLOPT_HTTPHEADER => array(
"Authorization: Basic xxxxxxxxxxxxxxxx",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl)
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
API Request Code
var settings = {
"async": true,
"crossDomain": true,
"url": "https://api.domain.com/?param&param&param…..",
"method": "POST",
"headers": {
"Authorization": "Basic xxxxxxxxxxxxxxxxxx",
"cache-control": "no-cache"
},
"data": {
"grant_type": “client_credentials"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
API Testing Tools
Paw Postman Swagger
paw.cloud getpostman.com swagger.io
API Types
•Public
•Authenticated
client_key / client_secret
•Public / Authenticated
API Providers
WordPress Rest API
domain.com/wp-json/wp/v2/posts
WordPress Rest API
WordPress Rest API
https://developer.wordpress.org/rest-api/reference/
https://chrome.google.com/webstore/detail/json-viewer/gbmdgpbipfallnflgajpaliibnhdgobh
Why use the
WordPress API
Headless CMS
Data Migrations
Mobile APP services
What is an API

What is an API

Editor's Notes

  • #2 Contrary to popular belief an API isn’t something performed by magical internet fairies and pixies, its something that I soon discovered is quite difficult to explain in layman’s terms so I decided to deep deeper and googled it to see how others explained what an API actually is!
  • #4 Errrrm, does that really make any sense…? Lets see what else we can understand….
  • #6 Well that kind of makes sense but its not that easy to understand right?
  • #8 Well kind of making little sense right?
  • #10 Hmm… still a little what the…..!!
  • #12 An application can be a website, a mobile app, a database or simply a set dataset like a CRM or social platform
  • #28 Public is open to all Authenticated requires setting up an application with the api provider, in exchange you get things like a key and a secret that you can use to make more complex requests.
  • #29 All apis are different, some a really good, some are ok and some are pretty bad >< Which leads me on to my next question, hands up if you know about the WP API? Hands up if you’ve used the WP API?