aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: bea9fd40691c2520b79c381f581315bba1cbf640 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# HEROES API

Make your Heroes API

## Installation

### Standar installation

heroeapi require of **python packages** and **MongoDB** for work.

After running your **MongoDB** set configuration:

Write `.env` file:

```sh
API_DEBUG=False
DB_NAME=heroes  # changeme
DB_HOST=127.0.0.1
DB_PORT=27017
DB_USER=root  # changeme
DB_PASS=example  # changeme
DB_AUTH=admin
JWT_SECRET_KEY=eo7aiHie4aeth4eteeho7ahC7yeetohsi7a  # changeme
USER_ENABLE_REGISTER=True
```

```console
$ git clone https://c.hgit.ga/software/heroeapi.git
```

```console
$ virtualenv -p python3 venv
```

```console
$ pip install -r requirements.txt
```

```console
$ python wsgi.py
```

### Docker Compose

Set configuration file `.env` on **heroeapi app** and  `.db.env` **mongo database**

Write `.env`:

```sh
# APP
API_DEBUG=False
DB_NAME=heroes  # changeme
DB_HOST=127.0.0.1
DB_PORT=27017
DB_USER=root
DB_PASS=example  # changeme
DB_AUTH=admin
JWT_SECRET_KEY=eo7aiHie4aeth4eteeho7ahC7yeetohsi7a  # changeme
USER_ENABLE_REGISTER=True

# GUNICORN
GUNICORN_TIMEOUT=30
GUNICORN_NUM_WORKERS=4
```

Write `.db.env`:

```sh
MONGO_INITDB_ROOT_USERNAME=root  # changeme
MONGO_INITDB_ROOT_PASSWORD=example  # changeme
MONGO_INITDB_DATABASE=admin
```

Write `docker-compose.yml`:

```yaml
version: '3.5'

services:
  app:
    image: rusian/heroesapi
    container_name: heroeapi
    env_file: .env
    networks:
      - heroeapi
    ports:
      - "5000:5000"
    tty: true
    restart: "always"

  mongo:
    image: mongo:4.4.12-focal
    container_name: heroeapi_db
    networks:
      - heroeapi
    restart: always
    command: [--auth]
    env_file:
      - .db.env
    volumes:
      - ./heroeapi_db:/data/db
    ports:
      - "27017:27017"

networks:
  heroeapi:
    driver: bridge
```

```console
$ docker-compose up -d
```

### Generate image from build

```console
$ docker build --tag rusian/heroesapi -f Dockerfile .
```

## Usage

Check `test` directory for some examples.
Remember that you must first create the **user** to be able to add a **Hero**

## API References

#### Heroes

| Reference                      | Method | Purpose                                                                    |
|--------------------------------|--------|----------------------------------------------------------------------------|
| /api/v1/heroes                 | GET    | Returns all information of the character.                                  |
| /api/v1/heroes/:id             | GET    | Search by character id. Returns all information of the character.          |
| /api/v1/heroes/:id             | POST   | Add of information of the character (only Admin)                           |
| /api/v1/heroes/:id             | DELETE | Delete character by id (only Admin)                                        |
| /api/v1/heroes/:id             | PUT    | Update character by id (only Admin)                                        |
| /api/v1/heroes/:id/powerstats  | GET    | Returns JSON Array of all powerstats of given character.                   |
| /api/v1/heroes/:id/biography   | GET    | Returns JSON Array of character's biography.                               |
| /api/v1/heroes/:id/appearance  | GET    | Returns JSON Array of character's appearance.                              |
| /api/v1/heroes/:id/work        | GET    | Returns JSON Array of character's work i.e. occupation and operation base. |
| /api/v1/heroes/:id/connections | GET    | Returns JSON Array of character's connections.                             |
| /api/v1/heroes/:id/image       | GET    | Returns image url of the character.                                        |
| /api/v1/heroes/search/name     | GET    | Search character by name. Returns character id.                            |


###### /api/v1/heroes/id/powerstats

This API call provides all powerstats for the given character. The powerstats are as follows:

- Intelligence
- Strength
- Speed
- Durability
- Power
- Combat

###### /api/v1/heroes/id/biography

This API call gives the biographical stats of the character. They are:

- Full Name
- Alter Egos
- Aliases
- Place of Birth
- First Appearance
- Publisher
- Alignment

###### /api/v1/heroes/id/appearance

This API call provides the appearance of the character. The various statistics are :

- Gender
- Race
- Height
- Weight
- Eye Color
- Hair Color

###### /api/v1/heroes/id/work

This API lists the work/occupation of the character. They are:

- Occupation
- Base of operation

###### /api/v1/heroes/id/connections

This call lists out the connections of the character.

- Group Affiliation
- Relatives

###### /api/v1/heroes/id/image

This provides the image for the character, if exists.

- image

###### /api/v1/heroes/search/name

This API call helps you in finding the character-id of a character by searching it's name.

#### Users

| Reference           | Method | Purpose                                       |
|---------------------|--------|-----------------------------------------------|
| /api/v1/users       | GET    | Returns all information of users (only Admin) |
| /api/v1/users/:id   | GET    | Search by character id (only Admin)           |
| /api/v1/users/:id   | POST   | Add of information of the user (only Admin)   |
| /api/v1/users/:id   | DELETE | Delete user by id (only Admin)                |
| /api/v1/users/:id   | PUT    | Update user by id (only Admin)                |
| /api/v1/auth/signup | POST   | Create user                                   |
| /api/v1/auth/token  | POST   | Generate Token                                |

## LICENSE

This work is licensed under the [GNU GPLv3+](LICENSE)