Skip to content

Commit f67a04b

Browse files
authored
Merge pull request #130 from fastlabel/feature/improved-local-dev
Fix POST response control without payload and Base URL can be changed
2 parents 9ea815b + 597a31c commit f67a04b

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ Create a new dataset.
21152115
```python
21162116
dataset = client.create_dataset(
21172117
name="Japanese Dogs",
2118-
slug="japanese_dogs",
2118+
slug="japanese-dogs",
21192119
type="image"
21202120
)
21212121
```
@@ -2128,7 +2128,7 @@ See API docs for details.
21282128
{
21292129
'id': 'YOUR_DATASET_ID',
21302130
'name': 'Japanese Dogs',
2131-
'slug': 'japanese_dogs',
2131+
'slug': 'japanese-dogs',
21322132
'type': 'image',
21332133
'createdAt': '2022-10-31T02:20:00.248Z',
21342134
'updatedAt': '2022-10-31T02:20:00.248Z'
@@ -2164,7 +2164,7 @@ datasets = client.get_datasets(
21642164
)
21652165
```
21662166

2167-
If you wish to retrieve more than 1000 data sets, please refer to the Task [sample code](#get%20tasks).
2167+
If you wish to retrieve more than 1000 data sets, please refer to the Task [sample code](#get-tasks).
21682168

21692169
### Update Dataset
21702170

@@ -2250,7 +2250,7 @@ dataset_objects = client.get_dataset_objects(
22502250
)
22512251
```
22522252

2253-
If you wish to retrieve more than 1000 data sets, please refer to the Task [sample code](#get%20tasks).
2253+
If you wish to retrieve more than 1000 data sets, please refer to the Task [sample code](#get-tasks).
22542254

22552255
### Delete Dataset Object
22562256

fastlabel/api.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
from .exceptions import FastLabelException, FastLabelInvalidException
66

7-
FASTLABEL_ENDPOINT = "https://api.fastlabel.ai/v1/"
8-
97

108
class Api:
119

10+
base_url = "https://api.fastlabel.ai/v1/"
1211
access_token = None
1312

1413
def __init__(self):
14+
if os.environ.get("FASTLABEL_API_URL"):
15+
self.base_url = os.environ.get("FASTLABEL_API_URL")
1516
if not os.environ.get("FASTLABEL_ACCESS_TOKEN"):
1617
raise ValueError("FASTLABEL_ACCESS_TOKEN is not configured.")
1718
self.access_token = "Bearer " + os.environ.get("FASTLABEL_ACCESS_TOKEN")
@@ -27,7 +28,7 @@ def get_request(self, endpoint: str, params=None) -> dict:
2728
"Content-Type": "application/json",
2829
"Authorization": self.access_token,
2930
}
30-
r = requests.get(FASTLABEL_ENDPOINT + endpoint, headers=headers, params=params)
31+
r = requests.get(self.base_url + endpoint, headers=headers, params=params)
3132

3233
if r.status_code == 200:
3334
return r.json()
@@ -52,9 +53,7 @@ def delete_request(self, endpoint: str, params=None) -> dict:
5253
"Content-Type": "application/json",
5354
"Authorization": self.access_token,
5455
}
55-
r = requests.delete(
56-
FASTLABEL_ENDPOINT + endpoint, headers=headers, params=params
57-
)
56+
r = requests.delete(self.base_url + endpoint, headers=headers, params=params)
5857

5958
if r.status_code != 204:
6059
try:
@@ -77,10 +76,12 @@ def post_request(self, endpoint, payload=None):
7776
"Content-Type": "application/json",
7877
"Authorization": self.access_token,
7978
}
80-
r = requests.post(FASTLABEL_ENDPOINT + endpoint, json=payload, headers=headers)
79+
r = requests.post(self.base_url + endpoint, json=payload, headers=headers)
8180

8281
if r.status_code == 200:
8382
return r.json()
83+
elif r.status_code == 204:
84+
return
8485
else:
8586
try:
8687
error = r.json()["message"]
@@ -102,7 +103,7 @@ def put_request(self, endpoint, payload=None):
102103
"Content-Type": "application/json",
103104
"Authorization": self.access_token,
104105
}
105-
r = requests.put(FASTLABEL_ENDPOINT + endpoint, json=payload, headers=headers)
106+
r = requests.put(self.base_url + endpoint, json=payload, headers=headers)
106107

107108
if r.status_code == 200:
108109
return r.json()

0 commit comments

Comments
 (0)