Scala Enterprise API Request template

This is a simple template for sending requests.

Requests Template:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import requests
import json
from pprint import pprint

class ScalaAPIRequest():
def __init__(self, url, header, payload, method):
self.url = url
self.header = header
self.payload = payload
self.method = method

def send(self):
payload = json.dumps(self.payload)
if (self.method == "get"):
res = requests.get(self.url, headers=self.header, data=payload)
elif (self.method == "post"):
res = requests.post(self.url, headers=self.header, data=payload)
self.res = res
self.res_content = json.loads(res.content.decode("utf-8"))

def show_result(self):
pprint(self.res_content, indent=2)

def get_content(self, key):
return self.res_content[key]