You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this guide you will learn how to build a **JSON API** for ```Pets``` and persist them into a **relational database** using {{modlink "jdbi"}} module.
4
+
In this guide you will learn how to build a **JSON API** for ```Pets``` and persist them into a **relational database** using the {{modlink "jdbi"}} module.
5
5
6
-
[JDBI](http://jdbi.org/) is a SQL convenience library for Java. It attempts to expose relational database access in idiommatic Java, using collections, beans, and so on, while maintaining the same level of detail as JDBC. It exposes two different style APIs, a fluent style and a sql object style.
6
+
[JDBI](http://jdbi.org/) is a SQL convenience library for Java. It attempts to expose relational database access in idiomatic Java, using collections, beans, and so on, while maintaining the same level of detail as JDBC. It exposes two different style APIs, a fluent style and a sql object style.
7
7
8
8
# requirements
9
9
10
-
Make sure you have all these software installed it in your computer:
10
+
Make sure you have the following installed on your computer:
11
11
12
12
* A text editor or IDE
13
13
* {{java}} or later
@@ -21,7 +21,7 @@ Open a terminal/console and paste:
@@ -41,7 +41,7 @@ Add the {{modlink "jackson"}} dependency to your project:
41
41
</dependency>
42
42
```
43
43
44
-
Got to `App.java` and add the module:
44
+
Go to `App.java` and add the module:
45
45
46
46
```java
47
47
importorg.jooby.json.Jackson;
@@ -101,7 +101,7 @@ The ```mem``` or ```fs``` are special databases. In order to use them we need th
101
101
</dependency>
102
102
```
103
103
104
-
> **NOTE**: If you want to connect to `mySQL` database (or any other), then you'll have to add the ```mySQL Java Driver``` to your project and define the connection properties like:
104
+
> **NOTE**: If you want to connect to a database other than the embedded ```mem```or ```fs```, like e.g. `mySQL`, then you'll have to add the ```mySQL Java Driver``` to your project and define the connection properties like this:
105
105
>
106
106
> ```
107
107
> db.url = "jdbc:mysql//localhost/pets"
@@ -113,7 +113,7 @@ The ```mem``` or ```fs``` are special databases. In order to use them we need th
113
113
114
114
We are going to create a database schema at application startup time:
115
115
116
-
* Define a `schema` property in ```conf/application.conf``` like:
116
+
* Define a `schema` property in ```conf/application.conf``` like this:
117
117
118
118
```
119
119
schema = """
@@ -160,7 +160,7 @@ With a database ready, we are going to build our *JSON API*.
160
160
161
161
## creating a repository
162
162
163
-
[The SQL Object API](http://jdbi.org/sql_object_overview/) provides a declarative mechanism for a common [JDBI](http://jdbi.org/) usage – creation of DAO type objects where one method generally equates to one SQL statement. To use the SQL Object API, create an interface annotated to declare the desired behavior, like so:
163
+
[The SQL Object API](http://jdbi.org/sql_object_overview/) provides a declarative mechanism for a common [JDBI](http://jdbi.org/) usage – creation of DAO type objects where one method generally equates to one SQL statement. To use the SQL Object API, create an interface annotated to declare the desired behavior, like this:
164
164
165
165
```java
166
166
{{source "PetRepository.java"}}
@@ -222,7 +222,7 @@ You'll see an error page because we didn't persist any pet yet. Let's see how to
222
222
223
223
## save a pet
224
224
225
-
So far, we see how to query pets by ID or listing all them, it is time to see how to creates a new pet:
225
+
So far, we've seen how to query pets by ID or listing all them, it is time to see how to create a new pet:
226
226
227
227
```java
228
228
{
@@ -291,7 +291,7 @@ So far, we see how to query pets by ID or listing all them, it is time to see ho
291
291
292
292
# quick preview
293
293
294
-
API is ready, let's see how it looks like:
294
+
The API is ready, let's see how it looks like:
295
295
296
296
```java
297
297
{
@@ -332,22 +332,22 @@ API is ready, let's see how it looks like:
332
332
}
333
333
```
334
334
335
-
Not bad, ugh?
335
+
Not bad, huh?
336
336
337
-
Isn't, but did you see we have to repeat the `/api/pets` pattern for each of our routes?
337
+
But did you notice that we have to repeat the `/api/pets` pattern for each of our routes?
338
338
339
339
Let's fix that with {{javadoc "Jooby" "use" "java.lang.String"}}:
340
340
341
341
```java
342
342
{{source mainclass}}
343
343
```
344
344
345
-
Better now! The ```use``` method has many meanings in **Jooby**, If we use pass a ```String``` we can group route under a same path pattern.
345
+
That's better! The ```use``` method has many meanings in **Jooby**, If we use pass a ```String``` we can group routes under the same path pattern.
346
346
347
347
# conclusion
348
348
349
-
As you already see, building an API that saves data in a **database** is very simple. Code looks clean and simple thanks to {{modlink "jdbi"}} module.
349
+
As you've already seen, building an API that saves data in a **database** is very easy. The code looks clean and simple thanks to the {{modlink "jdbi"}} module.
350
350
351
-
The {{modlink "jdbi"}} module makes perfect sense if you want to have full control on your SQL queries, or if you don't like **ORM** tools too.
351
+
The {{modlink "jdbi"}} module makes perfect sense if you want to have full control of your SQL queries, or if you prefer not to use **ORM** tools.
0 commit comments