--- /dev/null
+info:
+ name: Define a word
+ type: http
+ seq: 2
+
+http:
+ method: GET
+ url: "{{api.base_url}}/words/:word/definition"
+ params:
+ - name: word
+ value: chien
+ type: path
+ auth: inherit
+
+settings:
+ encodeUrl: true
+ timeout: 0
+ followRedirects: true
+ maxRedirects: 5
http:
method: GET
- url: http://localhost:8080/words/:word/translation
+ url: "{{api.base_url}}/words/:word/translation"
params:
- name: word
- value: voiture
+ value: grenouille
type: path
auth: inherit
info:
name: larousse API
+config:
+ proxy:
+ inherit: true
+ config:
+ protocol: http
+ hostname: ""
+ port: ""
+ auth:
+ username: ""
+ password: ""
+ bypassProxy: ""
+
+request:
+ variables:
+ - name: api.base_url
+ value: https://lang.frustrated-labs.net
+ disabled: true
+ - name: api.base_url
+ value: http://localhost:8080
bundled: false
extensions:
bruno:
--- /dev/null
+package net.frustratedfunctor.definitions;
+
+import io.quarkus.logging.Log;
+import jakarta.enterprise.context.ApplicationScoped;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Element;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+@ApplicationScoped
+public class JsoupWordDefinitionRepository implements WordDefinitionRepository {
+ @Override
+ public List<String> definitionsForWord(String word) {
+ try {
+ final var larousseUrl = URI.create("https://www.larousse.fr/dictionnaires/francais/" + word).toURL();
+ final var doc = Jsoup.parse(larousseUrl, 10_000);
+ return doc
+ .select("li.DivisionDefinition")
+ .stream()
+ .map(Element::ownText)
+ .toList();
+ } catch (Exception e) {
+ Log.error("Error while fetching word definitions", e);
+ return new ArrayList<>();
+ }
+ }
+}
package net.frustratedfunctor.definitions;
-public record WordDefinition() {
+import java.util.List;
+
+public record WordDefinition(
+ String word,
+ List<String> definitions
+) {
}
package net.frustratedfunctor.definitions;
+import java.util.List;
+
public interface WordDefinitionRepository {
+
+ /**
+ * Get a list of definitions for the given word.
+ *
+ * @param word The word to get definitions for.
+ * @return A list of found definitions for the word.
+ */
+ List<String> definitionsForWord(String word);
+
}
@Path("/words")
public class WordDefinitionResource {
+ private final WordDefinitionService definitions;
+
+ public WordDefinitionResource(WordDefinitionService definitions) {
+ this.definitions = definitions;
+ }
+
@Path("/{word}/definition")
@GET
@Produces(MediaType.APPLICATION_JSON)
public WordDefinition definition(@PathParam("word") String word) {
- return null;
+ return definitions.define(word);
}
}
@ApplicationScoped
public class WordDefinitionService {
+
+ private final WordDefinitionRepository definitions;
+
+ public WordDefinitionService(WordDefinitionRepository definitions) {
+ this.definitions = definitions;
+ }
+
+ public WordDefinition define(String word) {
+ return new WordDefinition(
+ word,
+ definitions.definitionsForWord(word)
+ );
+ }
+
}
quarkus.kubernetes.namespace=default
quarkus.kubernetes.service-type=node-port
quarkus.otel.exporter.otlp.endpoint=http://localhost:4317
+%prod.quarkus.otel.exporter.otlp.endpoint=http://otel-collector.default.svc.cluster.local:4317
quarkus.application.name=larousse-api
quarkus.otel.simple=true
%prod.quarkus.otel.simple=false