All about DataSince, DataEngineering and ComputerScience
View the Project on GitHub datainsightat/DataScience_Examples
Letter | Word | Meaning |
---|---|---|
A | Application | Software that does a task |
P | Programming | Program that does the task in the Application |
I | Interface | Place to the program to run |
Advantages
API Mashup: An API that is calling other APIs.
API that uses the internet. All web services are APIs, but not all APIs are web services.
Web services use:
http | REQUEST | RESPONSE |
---|---|---|
startline | Version (1.1), Method, Folders, Parameters | Version (1.1), Status |
headers | Host (www.google.com), Token | Cookies, Html |
blank line | ||
body | Username, Password | Html |
REQUEST | RESPONSE | |
---|---|---|
Name | Start Line, Request Line | Start Line, Response Line, Status Line |
HTTP Version | HTTP/1.1 | HTTP/1.1 |
Method | GET, POST, PUT, DELETE | - |
API Program Folder Location | /search | - |
Parameters | ?q=tuna | - |
Status | - | 200 OK |
Format | Method(space)API Program Folder+Parameters(space)HTTP Version | HTTP Version(space)Status code |
Example | GET /search?q=tuna HTTP/1.1 | HTTP/1.1 200 OK |
C.reate R.ead U.pdate D.elete
Method | Function | Itempodent (safe to repeat) |
---|---|---|
GET | Get information | yes |
POST | Create information | no |
PUT | Change Information | yes |
DELETE | Delete Information | yes |
Code | Description |
---|---|
1xx | Still running, wait |
2xx | Success |
3xx | Redirection |
4xx | Error from origin |
5xx | Error from destination |
test.xml
<?xml version="1.0"?>
<Pizza>
<Size>Small</Size>
<Toppings>
<Topping>Onions</Topping>
<Topping>Mushrooms</Topping>
</Toppings>
</Pizza>
test.json
{ "Pizza" : [
{"Size" : "Small",
"Toppings" : ["Onions","Mushrooms"],
},
{"Size" : "Large",
"Toppings" : ["Ham","Egg"],
}
]
}
Soap uses a WSDL (Web Services Description Language) that describes the web service. SOAP uses POST method.
Item | Content |
---|---|
Start Line | POST WSL HTTP Version |
Header Line | Content-Type: text/xml |
Blank Line | - |
Body | XML envelope formed using WSDL |
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Header>
...
</soap:Header>
<soap:Body>
...
<soap:Fault>
...
</soap:Fault>
</soap:Body>
</soap:Envelope>
Item | Content |
---|---|
Start Line | GET, POST, PUT, DELETE, etc |
Header Line | All |
Blank Line | - |
Body | JSON, XML, Image, Html, … |
PUT
Authorization:Bearer ...
Accept:application/json
Content-Type:application/json
Content-Language:en-US
{
"availability": {
"shipToLocationAbailability": {
"quantity": 50
}
},
"condition": "NEW",
"product": {
"title": "An Item"
}
}
import tweepy
client_secret = '1eQr5yqKHnzXKJHCCsZ-fwo4YZ1OvXdd6k-5ub68aANVskxr8N'
ak = 'xxx'
aks = 'xxx'
at = 'xxx'
ats = 'xxx'
def OAuth():
try:
auth = tweepy.OAuthHandler(ak,aks)
auth.set_access_token(at,ats)
return auth
except Exception as e:
return None
oauth = OAuth()
apicall = tweepy.API(oauth)
apicall.update_status('Here is a sample tweet from the API call program.')
print('Tweet created')
Name | Authentication | Authorization | Examples |
---|---|---|---|
No Auth | N | N | Google search page |
Basic Auth | Y | N | |
Bearer Token | N | Y | Not many |
OAuth | Y | Y | Wayz |
Two Factor | Y | N | Git |
An application is authorized to acces certain ressources.
import requests
url = "https://httpbin.org/bearer"
payload = {}
headers = {
'Authorization': 'Bearer sdfgsdfg'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
A hook is an event that calls a webservice.
A microservice is a ‘small’ API.
Monolith Architecture | Microservice |
---|---|
One API | Many APIs |
API calls many programs | Specific API for each program |
+ scalable, language independent, specialised teams | |
- inconsistent |