Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter2 #12

Merged
merged 7 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ jobs:
build-book:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
Expand All @@ -18,9 +18,9 @@ jobs:
build-numbers:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
Expand All @@ -30,9 +30,9 @@ jobs:
build-gateway:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
Expand All @@ -42,9 +42,9 @@ jobs:
build-config-server:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
Expand All @@ -54,12 +54,12 @@ jobs:
build-authz-server:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'gradle'
- name: Build with Gradle
run: ./gradlew build -p authorization-server --info
run: ./gradlew build -p authorization-server --info
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Here is a short description of it.

This platform aims to store and get books of a bookstore.

### System View
### System View

```mermaid
C4Context
Expand Down Expand Up @@ -137,9 +137,9 @@ gitGraph:
| [OpenID Connect](https://openid.net/connect) | novice |]
| [Docker](https://docs.docker.com/) | novice |

### :wrench: Tools
### :wrench: Tools
#### If you want to execute this workshop locally
You must have set up these tools first:
You **MUST** have set up these tools first:
* [Java 17+](https://adoptium.net/temurin/releases/?version=17)
* [Gradle 7.5+](https://gradle.org/)
* [Docker](https://docs.docker.com/) & [Docker compose](https://docs.docker.com/compose/)
Expand Down Expand Up @@ -188,21 +188,23 @@ You then can open this project in either your local VS Code or directly in your
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#github.com/alexandre-touret/rest-apis-versioning-workshop.git)

##### With Github Codespaces
You can also [use Github Codespaces](https://docs.github.com/en/codespaces/).
You can also [use Github Codespaces](https://docs.github.com/en/codespaces/).
You can create a new one by [running "Code > Create codespace on main"](https://docs.github.com/en/codespaces/developing-in-codespaces/creating-a-codespace-for-a-repository#creating-a-codespace-for-a-repository).

You have then to run the command in the shell:

```jshelllanguage
pip install httpie
sdk install java 17.0.5-tem
sdk default java 17.0.5-tem
sdk install java 17.0.5-tem
sdk default java 17.0.5-tem
```

## :boom: Ready ?

> **Warning**
>
> I **strongly** suggest to fork this project into your personal GitHub namespace (aka your GitHub account).

:warning: I **strongly** suggest to fork this project into your personal GitHub namespace (aka your GitHub accounb).
You then can change the URL mentioned above to link GitHub and Gitpod:

```markdown
Expand All @@ -213,4 +215,8 @@ or you can directly browse this URL (think to change the ``%%MY_NAMESPACE%%`` pr

``https://gitpod.io/#github.com/%%MY_NAMESPACE%%/rest-apis-versioning-workshop.git``

Now, you can start [the workshop](./docs/index.md) :tada:.

> **Note**
>
> You can now start [the workshop](./docs/index.md) :tada:.

2 changes: 1 addition & 1 deletion config-server/src/main/resources/config/rest-book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spring:
username: book
password: book
jpa:
database-platform: org.hibernate.dialect.PostgreSQL95Dialect
database-platform: org.hibernate.dialect.PostgreSQLDialect
hibernate:
ddl-auto: create-drop
cloud:
Expand Down
36 changes: 18 additions & 18 deletions docs/01-without_versioning.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# How to upgrade your API without versioning?

At this point we have our first customer : **John Doe** who uses our API with the current specification.
At this point we have our first customer : **John Doe** who uses our API with the current specification.

## Prerequisites


You have to start three new shells and run [rest-book](../rest-book), [rest-number](../rest-number) and [the gateway](../gateway) modules.

You have to start three new shells and run [rest-book](../rest-book), [rest-number](../rest-number), [authorization-server](../authorization-server)
and [the gateway](../gateway) modules.
As mentioned earlier, you must be at the root of the project (i.e., ``rest-apis-versioning-workshop``).

<details>
Expand All @@ -24,10 +23,7 @@ In the second one:
./gradlew bootRun -p rest-number
```

<<<<<<< HEAD
=======

>>>>>>> c516c41... Upgrade to Spring Boot 3
And in the last one:

```jshelllanguage
Expand Down Expand Up @@ -83,10 +79,10 @@ Now you can stop this service now by typin CTRL+C on the shell you started the r

In this chapter, we will update the [Book schema in the OpenAPI spec file](../rest-book/src/main/resources/openapi.yml) adding the attribute ``excerpt``.

This attribute is just the beginning of the [description attribute](../rest-book/src/main/resources/openapi.yml).
This attribute is (only for the workshop) the beginning of the [description attribute](../rest-book/src/main/resources/openapi.yml).
We will extract the first 100 characters.

1. Update the [OpenAPI spec file]((../rest-book/src/main/resources/openapi.yml)), add the ``excerpt`` attribute
1. Update the [OpenAPI spec file]((../rest-book/src/main/resources/openapi.yml)), add the ``excerpt`` attribute

```yaml
Book:
Expand Down Expand Up @@ -175,7 +171,7 @@ For instance:
```
</details>

You can also add a similar test in the [BookControllerIT](../rest-book/src/test/java/info/touret/bookstore/spring/book/controller/BookControllerIT.java) integration test.
You can also add a similar test in the [BookControllerIT](../rest-book/src/test/java/info/touret/bookstore/spring/book/controller/BookControllerIT.java) integration test.

For instance, you can add this assertion in the [``should_get_a_random_book``](../rest-book/src/test/java/info/touret/bookstore/spring/book/controller/BookControllerIT.java):

Expand All @@ -197,13 +193,13 @@ Now you can re-build your application and validate it by running tests.

6. Now, let's get a random book with an excerpt

You can restart your rest-book service
Restart your rest-book service

```jshelllanguage
./gradlew bootRun -p rest-book
```

You can check it manually by running the following command:
Check it manually by running the following command:

```jshelllanguage
http :8082/books/1098 --print b | jq .excerpt
Expand All @@ -214,7 +210,6 @@ You can also do that through the API Gateway:
```jshelllanguage
http :8080/books/1098 --print b | jq .excerpt
```

## Adding a new operation

You can then add a new operation ``getBookExcerpt``.
Expand Down Expand Up @@ -311,7 +306,7 @@ Run tests again:
./gradle build
```

You have now added new data and functionality to your API without any version :exclamation:
You have now added new data and functionality to your API without any version :exclamation:

## What about backward compatibility?

Expand All @@ -323,16 +318,21 @@ Copy paste this class in your [test source directory](../rest-book/src/test/java
operation created earlier.
You can rename it ``OldBookDto`` for example and put in the package ``info.touret.bookstore.spring.book.dto``.

Copy paste then your [BookControllerIT](../rest-book/src/test/java/info/touret/bookstore/spring/book/controller/BookControllerIT.java) integration test to [OldBookControllerIT](../rest-book/src/test/java/info/touret/bookstore/spring/book/controller/OldBookControllerIT.java).
Copy paste then your [BookControllerIT](../rest-book/src/test/java/info/touret/bookstore/spring/book/controller/BookControllerIT.java) integration test to [OldBookControllerIT](../rest-book/src/test/java/info/touret/bookstore/spring/book/controller/OldBookControllerIT.java).

In the [OldBookControllerIT](../rest-book/src/test/java/info/touret/bookstore/spring/book/controller/OldBookControllerIT.java)
, replace the ``BookDto`` class usage with the new one.
, replace the ``BookDto`` class usage with the new one.

You also have to modify the test ``should_get_a_random_book()``.
You can remove this line:
You can remove this line:

```java
assertNotNull(bookDto.getExcerpt());
```

See what happens and **explain it** :exclamation:
> **Note**
>
> See what happens and **explain it** :exclamation:
>
> [Go then to chapter 2](./02-first_version.md)

Loading