Skip to content

Commit f4cfe2a

Browse files
author
Matt Bernier
authored
Merge pull request #49 from noblehelm/add_usage_md
add USAGE.md
2 parents adf4a31 + c57c7db commit f4cfe2a

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

USAGE.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# INITIALIZATION
2+
3+
```python
4+
import python_http_client
5+
6+
host = "https://api.sendgrid.com"
7+
api_key = os.environ.get('SENDGRID_API_KEY')
8+
request_headers = {
9+
"Authorization": 'Bearer {0}'.format(api_key)
10+
}
11+
version = 3
12+
client = python_http_client.Client(host=host,
13+
request_headers=request_headers,
14+
version=version)
15+
```
16+
17+
# Table of Contents
18+
19+
* [CLIENT](#client)
20+
* [RESPONSE](#response)
21+
22+
<a name="response"></a>
23+
# RESPONSE
24+
25+
Response object holds the response or data from a return statement from a client API call. It has three main properties, status_code, headers and body, which can be retrieved via a simple call:
26+
27+
```python
28+
print(response.status_code)
29+
print(response.headers)
30+
print(response.body)
31+
```
32+
33+
<a name="client"></a>
34+
# CLIENT
35+
Client object that allows quick access a REST-like API. All methods return a Response object that can be treated with as explained in Response.
36+
37+
## GET
38+
HTTP request to retrieve information from a source.
39+
40+
```python
41+
response = client.api_keys.get()
42+
```
43+
44+
```python
45+
response = client.api_keys._(api_key_id).get()
46+
```
47+
48+
## POST
49+
HTTP request to send data to a source.
50+
51+
```python
52+
data = {
53+
"name": "My API Key",
54+
"scopes": [
55+
"mail.send",
56+
"alerts.create",
57+
"alerts.read"
58+
]
59+
}
60+
response = client.api_keys.post(request_body=data)
61+
# print(response) as shown above
62+
```
63+
64+
## PATCH
65+
HTTP request to update partial resources in a source.
66+
67+
```python
68+
data = {
69+
"name": "A New Hope"
70+
}
71+
response = client.api_keys._(api_key_id).patch(request_body=data)
72+
# print(response) as shown above
73+
```
74+
75+
## PUT
76+
HTTP request used to replace a collection or element in a source.
77+
78+
```python
79+
data = {
80+
"name": "The Empire Strikes Back",
81+
"scopes": [
82+
"user.profile.read",
83+
"user.profile.update"
84+
]
85+
}
86+
response = client.api_keys.put(request_body=data)
87+
# print(response) as shown above
88+
```
89+
90+
## DELETE
91+
HTTP request to delete elements in a source.
92+
93+
```python
94+
response = client.api_keys._(api_keys_id).delete()
95+
# print(response) as shown above
96+
```

0 commit comments

Comments
 (0)