Introducing Spring Framework
Introducing Spring Framework Introducing Spring Framework
Chapter 12 ■ Exposing a REST API select d.documentId, d.name, d.location, d.description as doc_desc, d.typeId, d.created, d.modified, t.name as type_name, t.description as type_desc, t.extension from documents d join types t on d.typeId = t.typeId select d.documentId, d.name, d.location, d.description as doc_desc, d.typeId, d.created, d.modified, t.name as type_name, t.description as type_desc, t.extension from documents d join types t on d.typeId = t.typeId where d.documentId = ? insert into documents (documentId,name,location,description, typeId, created, modified) values (?,?,?,?,?,?,?) update documents set name = ?, location = ?, description = ?, typeId = ?,modified = ? where documentId = ? delete from documents where documentId = ? 176
Chapter 12 ■ Exposing a REST API The only modification you made in the Listing 12-5 was adding the sql bean as a HashMap. Remember that instead of using individual properties for each SQL statement, now you’re going to use a map. Now, you can test the web application. You need to run the following command: gradle :ch12:jettyEclipseRun After you execute the preceding command, you can start testing each RESTful call. ■ ■Note In Chapter 10 you used the gradle :ch10:jettyRun command. But here you are using a more robust plugin for gradle that supports the latest version of the Jetty container. This is the jettyEclipse plugin that uses the latest servlet specification, version 3.0. You can find more information about how to define it in the book’s source code companion. HTTP-GET First, let’s go with HTTP-GET for the /documents resource. Figure 12-1 shows the result of executing the http://localhost:8080/mydocuments/documents URL. You need to remember that this data is located in the META-INF/data/ folder and is loaded in memory (using the HSQL) when the server is starting up. Figure 12-1. Response of the HTTP GET Method from http://localhost:8080/mydocuments/documents 177
- Page 123 and 124: Chapter 9 ■ Adding Persistence to
- Page 125 and 126: Chapter 9 ■ Adding Persistence to
- Page 127 and 128: Chapter 9 ■ Adding Persistence to
- Page 129 and 130: Chapter 9 ■ Adding Persistence to
- Page 131 and 132: Chapter 9 ■ Adding Persistence to
- Page 133 and 134: Chapter 10 ■ Showing Your Spring
- Page 135 and 136: Chapter 10 ■ Showing Your Spring
- Page 137 and 138: Chapter 10 ■ Showing Your Spring
- Page 139 and 140: Chapter 10 ■ Showing Your Spring
- Page 141 and 142: Chapter 10 ■ Showing Your Spring
- Page 143 and 144: Chapter 10 ■ Showing Your Spring
- Page 145 and 146: Chapter 11 ■ Integrating Your Spr
- Page 147 and 148: Chapter 11 ■ Integrating Your Spr
- Page 149 and 150: Chapter 11 ■ Integrating Your Spr
- Page 151 and 152: Chapter 11 ■ Integrating Your Spr
- Page 153 and 154: Chapter 11 ■ Integrating Your Spr
- Page 155 and 156: Chapter 11 ■ Integrating Your Spr
- Page 157 and 158: Chapter 11 ■ Integrating Your Spr
- Page 159 and 160: Chapter 11 ■ Integrating Your Spr
- Page 161 and 162: Chapter 11 ■ Integrating Your Spr
- Page 163 and 164: Chapter 11 ■ Integrating Your Spr
- Page 165 and 166: Chapter 11 ■ Integrating Your Spr
- Page 167 and 168: Chapter 12 Exposing a REST API Nowa
- Page 169 and 170: Chapter 12 ■ Exposing a REST API
- Page 171 and 172: Chapter 12 ■ Exposing a REST API
- Page 173: Chapter 12 ■ Exposing a REST API
- Page 177 and 178: Chapter 12 ■ Exposing a REST API
- Page 179 and 180: HTTP-DELETE Chapter 12 ■ Exposing
- Page 181 and 182: Chapter 13 Adding E-mail and Schedu
- Page 183 and 184: Chapter 13 ■ Adding E-mail and Sc
- Page 185 and 186: Chapter 13 ■ Adding E-mail and Sc
- Page 187 and 188: Chapter 13 ■ Adding E-mail and Sc
- Page 189 and 190: Chapter 13 ■ Adding E-mail and Sc
- Page 191 and 192: Part III Spring Framework Advanced
- Page 193 and 194: Chapter 14 ■ Using Dynamic Langua
- Page 195 and 196: Chapter 14 ■ Using Dynamic Langua
- Page 197 and 198: Chapter 14 ■ Using Dynamic Langua
- Page 199 and 200: Chapter 14 ■ Using Dynamic Langua
- Page 201 and 202: Chapter 15 ■ Spring Data Within Y
- Page 203 and 204: Chapter 15 ■ Spring Data Within Y
- Page 205 and 206: Chapter 15 ■ Spring Data Within Y
- Page 207 and 208: Chapter 15 ■ Spring Data Within Y
- Page 209 and 210: Chapter 15 ■ Spring Data Within Y
- Page 211 and 212: Chapter 15 ■ Spring Data Within Y
- Page 213 and 214: Chapter 15 ■ Spring Data Within Y
- Page 215 and 216: Chapter 16 ■ Messaging with Your
- Page 217 and 218: Chapter 16 ■ Messaging with Your
- Page 219 and 220: Chapter 16 ■ Messaging with Your
- Page 221 and 222: Chapter 16 ■ Messaging with Your
- Page 223 and 224: Chapter 16 ■ Messaging with Your
Chapter 12 ■ Exposing a REST API<br />
The only modification you made in the Listing 12-5 was adding the sql bean as a HashMap. Remember that<br />
instead of using individual properties for each SQL statement, now you’re going to use a map. Now, you can test the<br />
web application. You need to run the following command:<br />
gradle :ch12:jettyEclipseRun<br />
After you execute the preceding command, you can start testing each RESTful call.<br />
■ ■Note In Chapter 10 you used the gradle :ch10:jettyRun command. But here you are using a more robust plugin for<br />
gradle that supports the latest version of the Jetty container. This is the jettyEclipse plugin that uses the latest servlet<br />
specification, version 3.0. You can find more information about how to define it in the book’s source code companion.<br />
HTTP-GET<br />
First, let’s go with HTTP-GET for the /documents resource. Figure 12-1 shows the result of executing the<br />
http://localhost:8080/mydocuments/documents URL. You need to remember that this data is located in the<br />
META-INF/data/ folder and is loaded in memory (using the HSQL) when the server is starting up.<br />
Figure 12-1. Response of the HTTP GET Method from http://localhost:8080/mydocuments/documents<br />
177