11 abril 2024

04 abril 2024

Implement JWT authentication in a Spring Boot 3 application



Prerequisites

  • JDK 11 or higher 
  • Maven 3.8 or higher 
  • MySQL running on Docker 
  • An HTTP client such as Postman, Insomnia, cURL, etc.






20 novembro 2023

ChatGPT Integration with Spring Boot Application


OpenAI ChatGPT APIs
API (POST https://api.openai.com/v1/chat/completions) to generate responses to a prompt. 

What we need to send to invoke the OpenAI API?
  • Upon accessing the “Create Chat Completion” API link, the following information regarding endpoint, request, and response is visible.
  • Endpoint: POST https://api.openai.com/v1/chat/completions
  • Go to Playgroud and type any message e.g. “What is spring boot?”



https://platform.openai.com/api-keys






22 maio 2023

CompletableFuture and ExecutorService

CompletableFuture and ExecutorService 

ExecutorService
public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executor = Executors.newFixedThreadPool(3);
        Future futureResult = executor.submit(new Add(10, 20)); // 1
        Integer intermediateResult = futureResult.get(); // 2
        Future finalResult = executor.submit(new Multiply(intermediateResult)); // 3
        System.out.println(finalResult.get());
        executor.shutdown();
    }
CompletableFuture

 
public static void main(String[] args) throws ExecutionException, InterruptedException {
    Integer finalResult = CompletableFuture.supplyAsync(() -> add(10, 20))
            .thenApplyAsync(result -> multiply(result))
            .get();
    System.out.println(finalResult);
}
public static Integer add(int a, int b) {
    return a + b;

}
public static Integer multiply(int result) {
    return result * 15;
}



Source: medium.com/@anil.java.story