|
1 | | -# api-server-django |
| 1 | + |
| 2 | +# Django API Server |
| 3 | + |
| 4 | +Simple starter built with Python / Django Rest / Sqlite3 and JWT Auth. The authentication flow is based on [json web tokens](https://jwt.io). |
| 5 | + |
| 6 | +<br /> |
| 7 | + |
| 8 | +> Features: |
| 9 | +
|
| 10 | +- Simple, intuitive codebase - built for beginners (can be extended with ease) |
| 11 | +- Django / Django REST / Sqlite3 - a simple, easy to use backend |
| 12 | +- Authentication with JWT (JWT login, JWT logout) |
| 13 | +- Testing |
| 14 | +- Docker Support |
| 15 | +- [API Interface Descriptor](https://github.com/app-generator/api-server-Django/blob/master/media/api.postman_collection.json): POSTMAN Collection |
| 16 | +- Docker |
| 17 | +- Full-stack Samples that uses this backend |
| 18 | + - [React Node JS Berry](https://appseed.us/product/react-node-js-berry-dashboard) - open-source full-stack sample |
| 19 | + |
| 20 | +<br /> |
| 21 | + |
| 22 | +> Support: |
| 23 | +
|
| 24 | +- Github (issues tracker), Email: **support @ appseed.us** |
| 25 | +- **Discord**: [LIVE Support](https://discord.gg/fZC6hup) (registered AppSeed Users) |
| 26 | + |
| 27 | +<br /> |
| 28 | + |
| 29 | +![Django API Server - Open-source Django Starter provided by AppSeed.]() |
| 30 | + |
| 31 | +<br /> |
| 32 | + |
| 33 | +## Requirements |
| 34 | +- Django==3.2.5 |
| 35 | +- djangorestframework==3.12.4 |
| 36 | +- PyJWT==2.1.0 |
| 37 | +- django-cors-headers==3.7.0 |
| 38 | + |
| 39 | +<br /> |
| 40 | + |
| 41 | +## How to use the code |
| 42 | + |
| 43 | +**Clone the sources** |
| 44 | + |
| 45 | +```bash |
| 46 | +$ git clone https://github.com/app-generator/api-server-django.git |
| 47 | +$ cd api-server-django |
| 48 | +``` |
| 49 | + |
| 50 | +**Create a virtual environment** |
| 51 | + |
| 52 | +```bash |
| 53 | +$ virtualenv -p python3 venv |
| 54 | +$ source venv/bin/activate |
| 55 | +``` |
| 56 | + |
| 57 | +**Install dependencies** using pip |
| 58 | + |
| 59 | +```bash |
| 60 | +$ pip install -r requirements.txt |
| 61 | +``` |
| 62 | + |
| 63 | +**Start the API server** |
| 64 | + |
| 65 | +```bash |
| 66 | +$ python manage.py migrate |
| 67 | +$ python manage.py runserver |
| 68 | +``` |
| 69 | + |
| 70 | +The API server will start using the default port `8000`. |
| 71 | + |
| 72 | + |
| 73 | +<br /> |
| 74 | + |
| 75 | +### [Docker](https://www.docker.com/) execution |
| 76 | +--- |
| 77 | + |
| 78 | +> Get the code |
| 79 | +
|
| 80 | +```bash |
| 81 | +$ git clone https://github.com/app-generator/api-server-django.git |
| 82 | +$ cd api-server-django |
| 83 | +``` |
| 84 | + |
| 85 | +> Start the app in Docker |
| 86 | +
|
| 87 | +```bash |
| 88 | +$ docker-compose up -d --build |
| 89 | +``` |
| 90 | + |
| 91 | +Visit `http://localhost:5000` in your browser. The API server will be running. |
| 92 | + |
| 93 | + |
| 94 | +<br /> |
| 95 | + |
| 96 | +## API |
| 97 | + |
| 98 | +For a fast set up, use this POSTMAN file: [api_sample](https://github.com/app-generator/api-server-Django/blob/master/media/api.postman_collection.json) |
| 99 | + |
| 100 | +> **Register** - `api/users/signup` |
| 101 | +
|
| 102 | +``` |
| 103 | +POST api/users/signup |
| 104 | +Content-Type: application/json |
| 105 | +
|
| 106 | +{ |
| 107 | + "username":"test", |
| 108 | + "password":"pass", |
| 109 | + |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +<br /> |
| 114 | + |
| 115 | +> **Login** - `api/users/login` |
| 116 | +
|
| 117 | +``` |
| 118 | +POST /api/users/login |
| 119 | +Content-Type: application/json |
| 120 | +
|
| 121 | +{ |
| 122 | + "password":"pass", |
| 123 | + |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +<br /> |
| 128 | + |
| 129 | +> **Logout** - `api/users/logout` |
| 130 | +
|
| 131 | +``` |
| 132 | +POST api/users/logout |
| 133 | +Content-Type: application/json |
| 134 | +authorization: JWT_TOKEN (returned by Login request) |
| 135 | +
|
| 136 | +{ |
| 137 | + "token":"JWT_TOKEN" |
| 138 | +} |
| 139 | +``` |
| 140 | + |
| 141 | +<br /> |
0 commit comments