Skip to content

Commit

Permalink
Simple API endpoint (#6)
Browse files Browse the repository at this point in the history
* added simple router

* included basic router to the main
  • Loading branch information
HazalCiplak authored Dec 17, 2024
1 parent ad44d11 commit 2dab53e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
16 changes: 16 additions & 0 deletions spacy_keyword_extraction_api/api_router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import logging

from fastapi import APIRouter


LOGGER = logging.getLogger(__name__)


def create_api_router() -> APIRouter:
router = APIRouter()

@router.get("/v1/extract-keywords")
def extract_keywords(text: str):
return text.split()

return router
5 changes: 4 additions & 1 deletion spacy_keyword_extraction_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles

from spacy_keyword_extraction_api.api_router import create_api_router


LOGGER = logging.getLogger(__name__)


def create_app():
app = FastAPI()

app = FastAPI(docs_url=None, redoc_url=None)
app.include_router(create_api_router())

app.mount('/', StaticFiles(directory='static', html=True), name='static')

return app
18 changes: 18 additions & 0 deletions tests/unit_test/api_router_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from fastapi.testclient import TestClient
from fastapi import FastAPI

from spacy_keyword_extraction_api.api_router import create_api_router


def create_test_client():
app = FastAPI()
app.include_router(create_api_router())
client = TestClient(app)
return client


class TestExtractKeyword:
def test_should_return_keywords(self):
client = create_test_client()
response = client.get('/v1/extract-keywords', params={'text': 'some text'})
assert response.json() == ['some', 'text']
6 changes: 6 additions & 0 deletions tests/unit_test/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ def test_read_main():
client = TestClient(create_app())
response = client.get("/")
assert response.status_code == 200


def test_extract_keywords_endpoint_is_available():
client = TestClient(create_app())
response = client.get("/v1/extract-keywords", params={'text': 'some text'})
assert response.status_code == 200

0 comments on commit 2dab53e

Please sign in to comment.