Skip to content

rnhc1000/calculatorWeb

Repository files navigation

WebCalculator API Challenge

I was challenged to develop a WebCalculator RESTful API and this is how I tackled it...

Table of contents

Overview

This app is an API calculator supporting basic math operations and providing a random string generator. The goal is to evaluate how a dev face the challenge of building a RESTful API to be consumed by a ReactJS-based front-end app available at CalculatorWeb-UI.

Requirements

There are some specific requirements to be met, such as authentication and authorization, data persistence, paginated data recovery, consume services of other api -> Random.org API, authenticated access to endpoints and some other requirements.

The app has been coded using Java 21, Spring Boot 3.3.2, Gradle, Javadoc, Spring Security, Spring JPA, Spring Webflux, Flyway, Jackson, Lombok, OpenAPI, MySQL, Docker and hosted in an AWS EC2 instance with secure access provided by a NGINX SSL proxy reverse and being live at CalculatorWeb-API

I will let you give it a try using these credentials to taste it:
username: example@example.com, password: example.com

Click at CalculatorWeb-UI, load these credentials, authenticate and get a credit of 100.00 to do your maths!
Enjoy it....
Why don't you take a look at this short video....to see how it works...
Short Video


Project Structure

  • docs
    • javadocs
  • src
    • main
    • java
      • br.dev.ferreiras.calculatorweb
        • config
        • controller
          • handlers
        • dto
        • entity
        • enums
        • mapper
        • repository
        • services
          • exceptions
    • resources
      • db.migration
      • certs
    • test

Howto Build and Run

- MySQL Database : http://127.0.0.1:3306
- profile active: dev or prod
- service socket: 127.0.0.1:8095
- tweak a few knobs to get it up and running
"""
src.main.java.br.dev.ferreiras.calculatorweb.config.OpenApiConfiguration
...
public class OpenApiConfiguration {
@Bean
public OpenAPI defineOpenApi() {
  Server server = new Server();
  -> server.setUrl("http://127.0.0.1:8095"); <-
  server.setDescription("Development");
 ....
"""

To have a docker image follow the instructions of the dockerBuild.sh,
otherwise just Ctrl-Shift-F10 and voila...

Screenshot

Links

Built with

My Skills

Code Snippet

import java.util.List;

/**
 * 
 * @author ricardo@ferreiras.dev.br
 * @version 1.1.030901
 * @since 1.0
 *
 */

@Configuration
public class OpenApiConfiguration {
  @Bean
  public OpenAPI defineOpenApi() {
    Server server = new Server();
    server.setUrl("https://api.ferreiras.dev.br/");
    server.setDescription("Development");

    Contact myContact = new Contact();
    myContact.setName(":Ricardo Ferreira");
    myContact.setEmail("ricardo@ferreiras.dev.br");

    Info information = new Info()
            .title("Web Calculator")
            .version("1.0")
            .description("WebCalculatorAPI exposes endpoints to do maths at the backend and being persisted into a database")
            .contact(myContact);

    return new OpenAPI()
            .info(information)
            .addSecurityItem(new SecurityRequirement().addList("bearerAuth"))
            .components(
                    new Components()
                            .addSecuritySchemes("bearerAuth", new SecurityScheme()
                                    .type(SecurityScheme.Type.HTTP)
                                    .scheme("bearer")
                                    .bearerFormat("JWT")
                            )
            )
            .servers(List.of(server));
  }
}

Continued development

  • Unit Tests -OK
  • Provide a Json to FrontEnd including
    • delivery status of each operation to frontend - OK
    • count of operations consumed by subscriber - OK
  • Subscriber Authentication - OK
    • Spring JWT-OAuth2 - OK
  • Records Pagination - OK

Useful resources

Author

Ricardo Ferreira

- Portfolio

My Portfolio...

Releases

No releases published

Packages

No packages published