Skip to content

Commit

Permalink
Removed /api prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
steelcityamir committed Apr 23, 2024
1 parent 2291504 commit 6603651
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ docker run -p 8000:8000 steelcityamir/safe-content-ai:latest
Test using curl

```bash
curl -X POST "http://127.0.0.1:8000/api/v1/detect" \
curl -X POST "http://127.0.0.1:8000/v1/detect" \
-H "Content-Type: multipart/form-data" \
-F "file=@/path/to/your/image.jpeg"
```
Expand Down Expand Up @@ -76,13 +76,13 @@ uvicorn main:app --reload

## API usage

### POST /api/v1/detect
### POST /v1/detect

This endpoint allows users to upload an image file, which is then processed to determine if the content is NSFW (Not Safe For Work). The response includes whether the image is considered NSFW and the confidence level of the prediction.

#### Request

- **URL**: `/api/v1/detect`
- **URL**: `/v1/detect`
- **Method**: `POST`
- **Content-Type**: `multipart/form-data`
- **Body**:
Expand All @@ -102,7 +102,7 @@ This endpoint allows users to upload an image file, which is then processed to d
#### Curl

```bash
curl -X POST "http://127.0.0.1:8000/api/v1/detect" \
curl -X POST "http://127.0.0.1:8000/v1/detect" \
-H "Content-Type: multipart/form-data" \
-F "file=@/path/to/your/image.jpeg"
```
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def hash_data(data):
return hashlib.sha256(data).hexdigest()


@app.post("/api/v1/detect")
@app.post("/v1/detect")
async def classify_image(file: UploadFile = File(...)):
"""Function analyzing image."""
try:
Expand Down
10 changes: 5 additions & 5 deletions test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def compute_file_hash(file_path):


def test_read_main():
"""Tests that POST /api/v1/detect returns 200 OK with valid request body"""
"""Tests that POST /v1/detect returns 200 OK with valid request body"""
with open(FILE_NAME, "rb") as file:
response = client.post(
"/api/v1/detect",
"/v1/detect",
files={"file": (FILE_NAME, file, "image/jpeg")},
)
assert response.status_code == 200
Expand All @@ -36,8 +36,8 @@ def test_read_main():


def test_invalid_input():
"""Tests that POST /api/v1/detect returns 422 with empty request body"""
response = client.post("/api/v1/detect", files={})
"""Tests that POST /v1/detect returns 422 with empty request body"""
response = client.post("/v1/detect", files={})
assert response.status_code == 422


Expand All @@ -53,7 +53,7 @@ def test_cache_hit():
# Post the file to the endpoint as would happen in actual use
with open(FILE_NAME, "rb") as file:
response = client.post(
"/api/v1/detect",
"/v1/detect",
files={"file": (FILE_NAME, file, "image/jpeg")},
)

Expand Down

0 comments on commit 6603651

Please sign in to comment.