Skip to content

Commit d3904f5

Browse files
author
Jerome Louvel
committed
2 parents 41cab5a + cf628ed commit d3904f5

1 file changed

Lines changed: 57 additions & 74 deletions

File tree

modules/org.restlet.tutorial.webapi/README.md

Lines changed: 57 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66

77
* Git installed on your machine
88

9-
> The implementation is located [here](https://github.com/restlet/restlet-tutorial/tree/master/modules/org.restlet.tutorial.webapi)
10-
> You can clone this repository; the source code is located in `/modules/org.restlet.tutorial.webapi/` folder.
9+
The implementation is located [here](https://github.com/restlet/restlet-tutorial/tree/master/modules/org.restlet.tutorial.webapi). You can clone this repository; the source code is located in `/modules/org.restlet.tutorial.webapi/` folder.
1110

12-
> This example uses [Restlet Framework 2.3.0](http://restlet.com/download/current#release=stable&edition=jse&distribution=zip) (Java SE edition)
13-
and [H2 Database](www.h2database.com)
11+
This example uses [Restlet Framework 2.3.0](http://restlet.com/download/current) (Java SE edition)
12+
and [H2 Database](www.h2database.com).
1413

15-
> Restlet framework user guide is available [here](http://restlet.com/technical-resources/restlet-framework/guide/2.3/).
14+
Restlet Framework's User Guide is available [here](http://restlet.com/technical-resources/restlet-framework/guide/2.3/).
1615

1716
## Installation
1817

@@ -23,7 +22,7 @@ To install the Maven project:
2322
* Execute `mvn clean install`
2423
* For eclipse users : run `mvn eclipse:eclipse`
2524

26-
> For further instruction about running a Maven project : [Building a project with Maven](http://maven.apache.org/run-maven/index.html)
25+
For further instruction about running a Maven project : [Building a project with Maven](http://maven.apache.org/run-maven/index.html)
2726

2827
### Run this application
2928

@@ -36,34 +35,31 @@ Two files will be created :
3635

3736
They are both located in `/tmp` folder.
3837
To simplify the launch of the application, authentication and authorization are done in-memory
39-
(You should overwrite that with you own authentication system). Here are the login/password available:
38+
(You should overwrite that with your own authentication system). Here are the login/password available:
4039

4140
* admin/admin : to get admin role
4241
* owner/owner : to get owner role
4342
* user/user : to get user role
4443

45-
It uses HTTP Basic authentication.
44+
It uses HTTP Basic authentication. Learn more about authentication, authorization and security with Restlet Framework [here](http://restlet.com/learn/guide/2.3/core/security/).
4645

47-
> Learn more about authentication, authorization and security with Restlet Framework [here](http://restlet.com/learn/guide/2.3/core/security/).
48-
49-
> You can try this application easily with a REST client like [POSTMAN](http://www.getpostman.com/).
46+
You can interact with this application easily using a REST client like [POSTMAN](http://www.getpostman.com/).
5047

5148
## Database access
5249

5350
To visualize the database, open the H2 console in you browser (`http://localhost:8082`) and connect to the database with the JDBC URL `jdbc:h2:mem:restletWebApi;IFEXISTS=TRUE`.
5451

5552
## Description
5653

57-
This Web API contains 2 main resources :
58-
54+
This Web API contains 2 main resources:
5955
* Company : identified by an auto-generated id.
6056
* Contact : identified by its email. A contact can be part of a company and get a reference to it.
6157

6258
This is a diagram of the API :
6359

6460
![Diagram](https://github.com/restlet/restlet-tutorial/blob/master/modules/org.restlet.tutorial.webapi/images/RFWebAPIReferenceImplementation.png)
6561

66-
> A Web API definition can be generated with [APISpark extension (RF 2.3)](http://restlet.com/learn/guide/2.3/extensions/apispark).
62+
A Web API definition can be generated with [APISpark extension (V2.3)](http://restlet.com/learn/guide/2.3/extensions/apispark).
6763

6864
## Implementation choices
6965

@@ -76,98 +72,97 @@ This is a diagram of the API :
7672
## Next steps
7773

7874
Here are some instructions to go further with this project:
79-
8075
* Persistence layer
8176
* For each operation a new connection is created.
82-
It would be useful to use a connection pool like [DBCP](http://commons.apache.org/proper/commons-dbcp/).
77+
It would be useful to use a connection pool like [DBCP](http://commons.apache.org/proper/commons-dbcp/) or the built-in connection pool of your database's JDBC driver if available.
8378
* It is possible to totally dissociate the persistence layer from the Server Resources.
84-
It would allow the use of several persitence layers. It would also be possible to use dependency injection.
79+
It would allow the use of several persistence layers. It would also be possible to use dependency injection.
8580
* Authentication/Authorization
86-
* It is strongly recommended to store users/roles in a database instead of in-memory.
81+
* It is strongly recommended to store users/roles in a database or a user directory instead of in-memory.
8782
You can create a custom [SecretVerifier](http://restlet.com/technical-resources/restlet-framework/javadocs/2.3/jse/api/org/restlet/security/SecretVerifier.html)
88-
and [Enroler](http://restlet.com/technical-resources/restlet-framework/javadocs/2.3/jse/api/org/restlet/security/Enroler.html).
83+
and [Enroler](http://restlet.com/technical-resources/restlet-framework/javadocs/2.3/jse/api/org/restlet/security/Enroler.html) for this purpose.
8984
* It is possible to handle autorizations globally in a filter instead of at the beginning of each class.
9085
In fact, in this example, there is a repeating schema: the "user" role is required for GET methods,
9186
the "owner" role for to the others.
9287

9388
## Usage
9489

95-
> These examples are made using the JSON format but you can use XML or YAML if you want.
90+
These examples are made using the JSON format but you can use XML or YAML if you want.
9691

9792
### Ping resource
9893

9994
A resource `/ping` has been created which does not need authentication.
10095

10196
```GET http://localhost:9000/v1/ping```
10297

103-
![Ping Example](https://github.com/restlet/restlet-tutorial/blob/master/modules/org.restlet.tutorial.webapi/images/ping.png)
98+
It should return the ```Version: 1.0.0 running``` text in the HTTP response body.
10499

105-
> For the following examples, Basic Authentication is required
100+
For the following examples, Basic Authentication is required. Also, you should indicate the media type of the JSON document sent using a ```Content-Type: application/json``` HTTP header.
106101

107102
### Create a company
108103

109104
``` POST http://localhost:9000/v1/companies/```
110105

111106
```json
112107
{
113-
"name" : "Restlet",
108+
"name" : "GitHub",
114109
"duns" : "123456789",
115-
"address" : "2 API road",
116-
"zipCode" : "44300",
110+
"address" : "88 Colin P Kelly Jr St",
111+
"zipCode" : "94107",
117112
"creationDate" : "2014-01-01",
118-
"website" : "http://restlet.com",
119-
"city" : "Nantes",
113+
"website" : "github.com",
114+
"city" : "San Francisco",
120115
"phoneNumber" : "+1 555 555 555"
121116
}
122117
```
123118

124-
![POST Companies](https://github.com/restlet/restlet-tutorial/blob/master/modules/org.restlet.tutorial.webapi/images/POSTCompanies.png)
125-
126-
> The returned status is : `201 Created`.
127-
128-
The location of the created company is written is the "location" header.
129-
130-
![POST Companies headers](https://github.com/restlet/restlet-tutorial/blob/master/modules/org.restlet.tutorial.webapi/images/POSTCompaniesHeaders.png)
119+
The returned status is : `201 Created`. Note that the location of the created company is written is the ```Location``` HTTP header.
131120

132121
### Retrieve all created companies
133122

134123
```GET http://localhost:9000/v1/companies/```
135124

136-
> The trailing slash is optional : both `http://localhost:9000/v1/companies/` and `http://localhost:9000/v1/companies` will work.
137-
138-
It should retrieve :
125+
The trailing slash is optional : both `http://localhost:9000/v1/companies/` and `http://localhost:9000/v1/companies` will work. It should retrieve :
139126

140127
```json
141128
{
142-
"list" :
143-
[
144-
{
145-
"duns":"123456789",
146-
"address":"2 API road",
147-
"zipCode":"44300",
148-
"creationDate":"2014-01-01",
149-
"website":"http://restlet.com",
150-
"phoneNumber":"+1 555 555 555",
151-
"city":"Nantes",
152-
"name":"Restlet",
153-
"self":"/companies/1"
154-
}
155-
]
129+
"list": [
130+
{
131+
"duns": "738673861",
132+
"website": "restlet.com",
133+
"name": "Restlet",
134+
"self": "/companies/1"
135+
},
136+
{
137+
"duns": "947394731",
138+
"website": "google.com",
139+
"name": "Google",
140+
"self": "/companies/2"
141+
},
142+
{
143+
"duns": "123456789",
144+
"address": "88 Colin P Kelly Jr St",
145+
"zipCode": "94107",
146+
"creationDate": "2013-12-31",
147+
"website": "github.com",
148+
"phoneNumber": "+1 555 555 555",
149+
"city": "San Francisco",
150+
"name": "GitHub",
151+
"self": "/companies/3"
152+
}
153+
]
156154
}
157155
```
158156

159-
![GET Companies](https://github.com/restlet/restlet-tutorial/blob/master/modules/org.restlet.tutorial.webapi/images/GETCompanies.png)
160-
161-
> The `self` element refers to the location of the object : `http://localhost:9000/v1/companies/1`.
162-
> Try `GET http://localhost:9000/v1/companies/1` !
157+
The `self` element refers to the location of the object : `http://localhost:9000/v1/companies/3`. Try `GET http://localhost:9000/v1/companies/3`!
163158

164159
### Create a contact related to the created company
165160

166161
```PUT http://localhost:9000/v1/contacts/{email}```
167162

168-
with `{email}` representing the email of the contact you want to insert.
163+
with `{email}` representing the email of the contact you want to insert.
169164

170-
For this example, it is:
165+
For this example, it is:
171166
``` PUT http://localhost:9000/v1/contacts/gblondeau@restlet.com```
172167

173168
```json
@@ -191,20 +186,15 @@ You should get back:
191186
}
192187
```
193188

194-
![PUT Contacts](https://github.com/restlet/restlet-tutorial/blob/master/modules/org.restlet.tutorial.webapi/images/PUTContacts.png)
189+
The returned status is : `201 Created`.
195190

196-
> The returned status is : `201 Created`.
197-
198-
> The field company is a reference to the location of the company, with 1 the id of the company.
199-
ie : /companies/1 refers to http://localhost:9000/v1/companies/1
191+
The property company is a reference to the location of the company, with 1 the id of the company. ie : /companies/1 refers to http://localhost:9000/v1/companies/1
200192

201193
### Retrieve the list of created contacts
202194

203195
```GET http://localhost:9000/v1/contacts```
204196

205-
> The trailing slash is optional : both ```http://localhost:9000/v1/contacts/``` and ```http://localhost:9000/v1/contacts``` will work.
206-
207-
It should retrieve :
197+
The trailing slash is optional : both ```http://localhost:9000/v1/contacts/``` and ```http://localhost:9000/v1/contacts``` will work. It should retrieve :
208198

209199
```json
210200
{
@@ -222,9 +212,7 @@ It should retrieve :
222212
}
223213
```
224214

225-
![GET Contacts](https://github.com/restlet/restlet-tutorial/blob/master/modules/org.restlet.tutorial.webapi/images/GETContacts.png)
226-
227-
> The field company is a reference to the location of the company
215+
The property company is a reference to the location of the company.
228216

229217
To display the company information, add the following query parameter : ```?strategy=load```
230218

@@ -258,8 +246,6 @@ It should retrieve :
258246
}
259247
```
260248

261-
![GET Contacts](https://github.com/restlet/restlet-tutorial/blob/master/modules/org.restlet.tutorial.webapi/images/GETContactsLoad.png)
262-
263249
### Modify an existing contact
264250

265251
```PUT http://localhost:9000/v1/contacts/gblondeau@restlet.com```
@@ -285,7 +271,4 @@ It should retrieve:
285271
}
286272
```
287273

288-
![PUT Contacts](https://github.com/restlet/restlet-tutorial/blob/master/modules/org.restlet.tutorial.webapi/images/PUTContacts2.png)
289-
290-
> This time a ```200 OK ``` is returned because it is not a creation but an update.
291-
274+
This time a ```200 OK ``` is returned because it is not a creation but an update.

0 commit comments

Comments
 (0)