Git Product home page Git Product logo

widget-rest-api-spring's Introduction

Widget API

Summary

Sample RESTful API for doing basic CRUD operations on widgets.
Two different repository implementation exist in the service:

  • ConcurrentHashMap
  • H2

Operation results of widgets are same, they do not depend on the storage type.

This app is written with Java 11 & SpringBoot framework.

Build the app & run tests

$ mvn clean install  -> (with default profile, via in-memory)
$ mvn clean install -Dspring.profiles.active=in-memory  -> (to run integration tests via in-memory ConcurrentHashMap)
$ mvn clean install -Dspring.profiles.active=h2 -> (to run integration tests via h2 datasource)

Run the app with 2 different profiles

This will use ConcurrentHashMap and ConcurrentSkipListMap to store widgets and index widgets for fast retrieval:

$ mvn spring-boot:run
$ mvn spring-boot:run -Dspring-boot.run.profiles=in-memory

This will use H2 in memory DB to store widgets which will use DB indexes for fast retrieval:

$ mvn spring-boot:run -Dspring-boot.run.profiles=h2

If profile is not provided, default datasource will be ConcurrentHashMap.

If you would like to query data in H2, go to http://localhost:8080/h2-console and use these credentials to login:

username: sa
password:

The application starts at port 8080.

Functionalities of API on widgets

  • GET - /v1/widgets -> Get widgets. Optional request parameters are limit, x0, y0, x1, y0. Limit should be between [1-500], default limit = 10 [x0,y0] & [x1,y1] represents the coordinates(two points) to filter which widgets are located in it.
  • GET - /v1/widgets/{id} -> Get a widget by id
  • POST - /v1/widgets -> Create a new widget. Mandatory fields: xIndex, yIndex, height, weight. Optional field: zIndex
  • PUT - /v1/widgets/{id} -> Update an existing widget. Mandatory fields: xIndex, yIndex, height, weight
  • DELETE - /v1/widgets/{id} -> Delete an existing widget

Tests

There are both unit test & integration tests written and can be find under /test Here is a test coverage of the service:

Test Coverage

widget-rest-api-spring's People

Contributors

gajduk avatar old-profile avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.