Skip to content

Commit

Permalink
Update Python service skel
Browse files Browse the repository at this point in the history
* Use `api` as API base instead of service namespace
* Update README with shared DB config setup
  • Loading branch information
reisingerf committed Sep 18, 2024
1 parent da41498 commit 356dfaf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
19 changes: 14 additions & 5 deletions skel/django-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ conda create -n hello-manager python=3.12
conda activate hello-manager
```

### DB setup

- Add database config to `../../../../../shared/init-db.sql` for centralised DB setup
```
CREATE ROLE hello_manager;
CREATE DATABASE hello_manager OWNER hello_manager;
```


### Make

- At app root, perform
Expand Down Expand Up @@ -109,17 +118,17 @@ python manage.py runserver_plus
```

```
curl -s http://localhost:8000/hlo/v1/hello | jq
curl -s http://localhost:8000/api/v1/hello | jq
```

```
curl -s http://localhost:8000/hlo/v1/hello/1 | jq
curl -s http://localhost:8000/api/v1/hello/1 | jq
```

Or visit in browser:
- http://localhost:8000/hlo/v1
- http://localhost:8000/hlo/v1/hello
- http://localhost:8000/hlo/v1/hello/1
- http://localhost:8000/api/v1
- http://localhost:8000/api/v1/hello
- http://localhost:8000/api/v1/hello/1

### API Doc

Expand Down
2 changes: 1 addition & 1 deletion skel/django-api/project_name/tests/test_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def test_get_api(self):
"""
python manage.py test {{project_name}}.tests.test_viewsets.HelloViewSetTestCase.test_get_api
"""
response = self.client.get('/hlo/v1/hello/')
response = self.client.get('/api/v1/hello/')
logger.info(response.json())
self.assertEqual(response.status_code, 200, 'Ok status response is expected')
3 changes: 1 addition & 2 deletions skel/django-api/project_name/urls/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from {{project_name}}.viewsets.helloworld import HelloWorldViewSet
from {{project_name}}.settings.base import API_VERSION

api_namespace = "hlo"
api_version = API_VERSION
api_base = f"{api_namespace}/{api_version}/"
api_base = f"api/{api_version}/"

router = OptionalSlashDefaultRouter()
router.register(r"hello", HelloWorldViewSet, basename="hello")
Expand Down

0 comments on commit 356dfaf

Please sign in to comment.