1
- #Java Web API
1
+ # Java Web API
2
+
2
3
A simple ** standalone web application** providing API.
3
4
4
5
The API gives access to database resources and returns data in ** JSON** .
@@ -9,7 +10,8 @@ Implemented with **DAO** pattern.
9
10
10
11
Tested on ** H2Database** v1.4.196.
11
12
12
- ##Configuration
13
+ ## Configuration
14
+
13
15
* Build using Maven ` mvn install `
14
16
* Create a new database
15
17
* you can find ** ready-to-go** database and .properties files in folder ` /example_db ` .
@@ -20,33 +22,57 @@ Tested on **H2Database** v1.4.196.
20
22
21
23
` example.properties `
22
24
```
23
- <pre>
24
- url=<i>url of your database</i>
25
- driver=<i>jdbc driver of your database</i>
26
- username=<i>login for your database</i>
27
- password=<i>password for your database</i>
28
- </pre>
25
+ url=*url of your database*
26
+ driver=*jdbc driver of your database*
27
+ username=*login for your database*
28
+ password=*password for your database*
29
29
```
30
30
* Run application with the following parameters:
31
31
* `-port [1024..49151]` - port number that will be used by server
32
32
* `-dbProps path` - **relative** path to _.properties_ file
33
33
* Now you are able to connect at localhost:_port_ and start sending requests!
34
34
35
- ##Authentication
35
+ ## Authentication
36
+
36
37
Every user of API has to pass his username and access token along with every request:
37
38
38
39
`/route?user=username&token=user_token&key1=val1&key2=val2...`
39
40
40
41
Of course, all parameters can occur in any order.
41
42
42
- ##Public routes
43
+ ## User roles
44
+
45
+ Every user is created with
46
+ * role - _user_ (standard user) or _admin_ (administrator),
47
+ * name,
48
+ * access token,
49
+ * usage limit.
50
+
51
+ After _limit_ requests, every user has to get his limit renewed by an admin.
52
+
53
+ ### Standard user
54
+
55
+ Can access all **public** routes of the API in terms of his usage limits.
56
+
57
+ ### Administrator
58
+
59
+ Can access **all routes** of the API in terms of his usage limits and has ability to:
60
+ * access all users' data,
61
+ * add new users,
62
+ * delete current users,
63
+ * renew current users' usage limits.
64
+
65
+ ## Public routes
66
+
43
67
API consists of 3 public routes:
44
68
* **/actors** - provides access to actors data
45
69
* **/films** - provides access to films data
46
70
* **/languages** - provides access to languages data
47
71
48
- ###GET Parameters
72
+ ### GET Parameters
73
+
49
74
#### All routes
75
+
50
76
All of the routes mentioned above provide:
51
77
* obtaining all records under given route
52
78
@@ -68,9 +94,10 @@ All of the routes mentioned above provide:
68
94
69
95
/languages?order=asc...
70
96
71
- ####Route-specific parameters
97
+ #### Route-specific parameters
98
+
99
+ ##### /actor
72
100
73
- #####/actor
74
101
* firstName
75
102
76
103
/actors?firstName=Woody...
@@ -80,7 +107,8 @@ All of the routes mentioned above provide:
80
107
/actors?lastName=Williams...
81
108
82
109
83
- #####/film
110
+ ##### /film
111
+
84
112
You can mix title and language with both minLength and maxLength.
85
113
86
114
* title
@@ -97,42 +125,26 @@ You can mix title and language with both minLength and maxLength.
97
125
98
126
* maxLength (with duration equal or less than)
99
127
100
- `/films?language=mandarin&maxLength=99...`
128
+ /films?language=mandarin&maxLength=99...
129
+
130
+ ##### /language
101
131
102
- #####/language
103
132
* name
104
133
105
134
/language?name=english...
106
135
107
- ##Admin routes
136
+ ## Admin routes
137
+
108
138
Non-public (accessible only to application's admins) part of the API has 2 routes:
109
139
* **/user** - provides access to users data
110
140
* **/admin** - provides access to mechanisms of user management
111
141
112
142
Operations on these routes don't subtract from your usage limit.
113
143
114
- ###User
115
- Every user is created with
116
- * role - _user_ (standard user) or _admin_ (administrator),
117
- * name,
118
- * access token,
119
- * usage limit.
120
-
121
- After _limit_ requests, every user has to get his limit renewed by an admin.
122
-
123
- ###Standard user
124
- Can access all **public** routes of the API in terms of his usage limits.
125
-
126
- ###Administrator
127
- Can access **all routes** of the API in terms of his usage limits and has ability to:
128
- * access all users' data,
129
- * add new users,
130
- * delete current users,
131
- * renew current users' usage limits.
144
+ ### GET Parameters
132
145
133
- ###GET Parameters
146
+ ##### /user
134
147
135
- #####/user
136
148
* as well as in public API, you can order and paginate the results as well as get multiple results
137
149
by listing many ids
138
150
@@ -156,7 +168,7 @@ by listing many ids
156
168
/user?filter=noaccess...
157
169
158
170
159
- #####/admin
171
+ ##### /admin
160
172
* action
161
173
* add
162
174
@@ -176,7 +188,7 @@ You can modify multiple records within one request, for example:
176
188
/admin?action=renew&id=1,2,4,8&limit=16,32,64,128
177
189
178
190
179
- ##Credits
191
+ ## Credits
180
192
Thanks to [@math-g](https://github.com/math-g) for porting Sakila (sample MySQL database) to H2 dialect.
181
193
182
194
0 commit comments