initializr/initializr-service-sample
Brian Clozel c1e222901d Update spring.io metadata strategy to use the new API
Prior to this commit, the Spring Boot metadata reader would use a legacy
API endpoint on spring.io to fetch the Spring Boot versions.
The current website is about to be retired for a different
infrastructure and we should take this opportunity to update the
endpoint we're using.

This commit updates the metadata reader strategy to now use the
`https://spring.io/api/projects/spring-boot/releases` endpoint to fetch
the relevant information. The JSON format itself changed slightly and
this commit adapts to the new format as well.

Closes gh-1369
2023-01-18 15:02:42 +01:00
..
src/main Update spring.io metadata strategy to use the new API 2023-01-18 15:02:42 +01:00
pom.xml Polish 2019-10-16 11:37:21 +02:00
README.adoc Update spring.io metadata strategy to use the new API 2023-01-18 15:02:42 +01:00

= Service sample

:docs: https://docs.spring.io/initializr/docs/current-SNAPSHOT/reference/html

This sample demonstrates how you can create your own service easily as described in the
{docs}/#create-instance[reference documentation].

== Running the service
You can start the service from the command line:

[indent=0]
----
    $ ../mvnw spring-boot:run
----

Or, better yet, run the `ServiceApplication` main method from your favourite IDE.

== Generating a project
If you go to `localhost:8080` with your browser, you'll get a json document that describes
the capabilities of the service. There are several ways you can generate a project.

If you have `HTTPie` installed, try the following:

[indent=0]
----
    $ http :8080
----

If you prefer to use `cURL`, try this instead:

[indent=0]
----
    $ curl localhost:8080
----

If you have the `spring` CLI installed, you can also use it as follows:

[indent=0]
----
    $ spring init --target http://localhost:8080 --list
----

Finally, you can configure your IDE to point to another service instance.

== Configuration
There are two main customizations to the sample.

=== Metadata Update Strategy
First, `ServiceApplication` has a dedicated strategy to update the metadata with the available Spring Boot versions from `https://spring.io`.
When you issue your first request, you should see something like the following:

[indent=0]
----
Fetching Spring Boot metadata from https://spring.io/api/projects/spring-boot/releases
----

On further request, you won't see this log entry as the content is cached.
There are no expiration set, so the available versions won't change until you restart the service.

=== Basic Metadata
The configuration in `application.yml` is very simple with a single `web` dependency that brings `spring-boot-starter-web`.
The default `groupId` for generated projects has been customized to `org.acme`.

You can experiment by adding more dependencies or other elements that drive how projects are generated.