Skip to content

Commit e22cad3

Browse files
committed
refactor(api): add /api/v1 prefix
1 parent db8c922 commit e22cad3

File tree

6 files changed

+13
-12
lines changed

6 files changed

+13
-12
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Once the server is running, you can use the translation API:
113113

114114
```bash
115115
# Translate text from English to Spanish
116-
curl -X POST "http://localhost:8000/translate" \
116+
curl -X POST "http://localhost:8000/api/v1/translate" \
117117
-H "Content-Type: application/json" \
118118
-d '{
119119
"text": "Hello, how are you?",
@@ -242,7 +242,7 @@ Where `<base64-encoded-credentials>` is the Base64 encoding of `username:passwor
242242

243243
```bash
244244
# Replace 'your_username' and 'your_password' with your credentials
245-
curl -X POST "http://localhost:8000/translate" \
245+
curl -X POST "http://localhost:8000/api/v1/translate" \
246246
-H "Content-Type: application/json" \
247247
-H "Authorization: Basic $(echo -n 'your_username:your_password' | base64)" \
248248
-d '{"text": "Hello world", "src_lang": "en", "tgt_lang": "fr"}'
@@ -252,7 +252,7 @@ or
252252

253253
```bash
254254
# Replace 'your_username' and 'your_password' with your credentials
255-
curl -X POST "http://localhost:8000/translate" \
255+
curl -X POST "http://localhost:8000/api/v1/translate" \
256256
-H "Content-Type: application/json" \
257257
-u "your_username:your_password" \
258258
-d '{

babeltron/app/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def create_app() -> FastAPI:
5656
docs_url="/docs",
5757
redoc_url="/redoc",
5858
openapi_url="/openapi.json",
59+
root_path="/api/v1",
5960
)
6061

6162
app.add_middleware(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "babeltron"
3-
version = "0.3.5"
3+
version = "0.3.6"
44
dynamic = ["version"]
55
description = "A Python-based REST API that leverages single multilingual models like mBERT to provide efficient text translation services"
66
authors = [

scripts/test-model-container.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ done
6060

6161
# Test translation
6262
echo "Testing translation..."
63-
RESPONSE=$(curl -s -X POST "http://localhost:8000/translate" \
63+
RESPONSE=$(curl -s -X POST "http://localhost:8000/api/v1/translate" \
6464
-H "Content-Type: application/json" \
6565
-d '{
6666
"text": "Hello, how are you?",

tests/unit/app/middlewares/test_auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def mock_request(self):
2525
credentials = base64.b64encode(b"test_user:test_password").decode()
2626
request = MagicMock(spec=Request)
2727
request.headers = Headers({"Authorization": f"Basic {credentials}"})
28-
request.url.path = "/api/translate"
28+
request.url.path = "/api/v1/translate"
2929
return request
3030

3131
@pytest.fixture
@@ -47,7 +47,7 @@ async def test_dispatch_with_invalid_credentials(self, middleware):
4747
credentials = base64.b64encode(b"wrong_user:wrong_password").decode()
4848
request = MagicMock(spec=Request)
4949
request.headers = Headers({"Authorization": f"Basic {credentials}"})
50-
request.url.path = "/api/translate"
50+
request.url.path = "/api/v1/translate"
5151

5252
mock_call_next = AsyncMock()
5353

@@ -69,7 +69,7 @@ async def test_dispatch_with_public_path(self, middleware, mock_public_request):
6969
async def test_dispatch_with_missing_auth_header(self, middleware):
7070
request = MagicMock(spec=Request)
7171
request.headers = Headers({})
72-
request.url.path = "/api/translate"
72+
request.url.path = "/api/v1/translate"
7373

7474
mock_call_next = AsyncMock()
7575

tests/unit/app/routers/test_translate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_translate_success(mock_translation_model, mock_get_model, client):
3636
"tgt_lang": "fr"
3737
}
3838

39-
response = client.post("/translate", json=test_data)
39+
response = client.post("/api/v1/translate", json=test_data)
4040
assert response.status_code == status.HTTP_200_OK
4141
data = response.json()
4242
assert data["translation"] == "Bonjour le monde"
@@ -74,7 +74,7 @@ def test_translate_with_model_type(mock_translation_model, mock_get_model, clien
7474
"model_type": "m2m100"
7575
}
7676

77-
response = client.post("/translate", json=test_data)
77+
response = client.post("/api/v1/translate", json=test_data)
7878
assert response.status_code == status.HTTP_200_OK
7979
data = response.json()
8080
assert data["translation"] == "Bonjour le monde"
@@ -102,7 +102,7 @@ def test_translate_model_not_loaded(mock_translation_model, mock_get_model, clie
102102
"tgt_lang": "fr"
103103
}
104104

105-
response = client.post("/translate", json=test_data)
105+
response = client.post("/api/v1/translate", json=test_data)
106106
assert response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR
107107
data = response.json()
108108
assert "detail" in data
@@ -134,7 +134,7 @@ def test_translate_model_error(mock_translation_model, mock_get_model, client):
134134
}
135135

136136
# Make the request
137-
response = client.post("/translate", json=test_data)
137+
response = client.post("/api/v1/translate", json=test_data)
138138

139139
# Check that we got a 500 error
140140
assert response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR

0 commit comments

Comments
 (0)