Skip to content

Instantly share code, notes, and snippets.

@afaqk9394
afaqk9394 / calculator.py
Created November 3, 2019 05:52
calculator
class Calculator(object):
def subtract(self, x, y):
return x-y
@afaqk9394
afaqk9394 / Troubleshoot-HTTP-responsecode.py
Created November 3, 2019 06:03
Troubleshoot a problem given the HTTP response code
import requests as req
response = req.get('https://github.com/apps/devnet-app')
print (response.status_code)
if response.status_code == 200:
print('Success!')
@afaqk9394
afaqk9394 / HTTP404.py
Created November 3, 2019 06:05
HTTP response code 404
import requests as req
response = req.get('https://github.com/apps/devnet-app/blah')
print (response.status_code)
if response.status_code == 200:
print('Success!')
@afaqk9394
afaqk9394 / APIauthentication.py
Created November 3, 2019 06:07
API authentication
import requests
import json
token = 'N3h5OJYadMUFBYqhxkX6XOozRBI4RJSZlsB3'
url = 'https://gorest.co.in/public-api/users'
data = {"email":"email7@example.com","first_name":"devnet","last_name":"associate","gender":"male"}
@afaqk9394
afaqk9394 / APIauthenticationmechanisms.py
Created November 3, 2019 06:08
API authentication mechanisms
import requests
import json
token = 'B3h5OJYadMUFBYqhxkX6XOozRBI4RJSZlsB3' #wrong token supplied
url = 'https://gorest.co.in/public-api/users'
data = {"email":"email8@example.com","first_name":"devnet","last_name":"associate","gender":"male"}
@afaqk9394
afaqk9394 / commonAPIauthenticationmechanisms.py
Created November 3, 2019 06:10
common API authentication mechanisms
import requests
from cryptography.hazmat.backends import default_backend
import jwt
import time
fname = 'devnet-app.2019-09-28.private-key.pem'
@afaqk9394
afaqk9394 / RESTAPI-requestslibrary.py
Created November 3, 2019 06:27
REST API using the requests library
import requests
import json
token = 'z8-sXMth942nOiQqXuikCNjbamrAlI2IjS7g'
url = 'https://gorest.co.in/public-api/users'
data = {"email":"em@tesla.com","first_name":"elon","last_name":"musk","gender":"male"}
@afaqk9394
afaqk9394 / RESTAPIGET.py
Created November 3, 2019 06:28
REST API GET Operation
import requests
import json
token = 'z8-sXMth942nOiQqXuikCNjbamrAlI2IjS7g'
url = 'https://gorest.co.in/public-api/users/1571'
result = requests.get(url,
@afaqk9394
afaqk9394 / REST-API-PATCH.py
Created November 3, 2019 06:29
REST API PATCH Operation
import requests
import json
token = 'z8-sXMth942nOiQqXuikCNjbamrAlI2IjS7g'
url = 'https://gorest.co.in/public-api/users/1571'
data = {"phone":"510-123-4567"}
@afaqk9394
afaqk9394 / REST-API-PUT.py
Created November 3, 2019 06:30
REST API PUT Operation
import requests
import json
token = 'z8-sXMth942nOiQqXuikCNjbamrAlI2IjS7g'
url = 'https://gorest.co.in/public-api/users/1571'
data = {"email":"ja@honest.com","first_name":"Jessica","last_name":"Alba","gender":"female"}