GithubHelp home page GithubHelp logo

web-skeleton's Introduction

Web-Skeleton

A skeleton project for WebSerivce based on Spring Boot

##Goals

  • Standalone server
  • Restful API with swagger to show API spec
  • Interceptor based authorization and performance calculation
  • Integration with database migration tool
  • JPA ready
  • Exception handling
  • Monitoring features

Standalone server

In this project, we use Spring Boot to power the application server. There are a couple advantages in this approach, some of them are below:

  • a mature framework with all Spring features
  • easy to develop/debug/deploy
  • quick start

Restful API

A example of restful API is given in UserController. I don't feel like there is much to say about how easy Spring helps to get all the parameters in URI.

However, I would love to mention that, with the help of Swagger, your documentation writing time is saved.

Interceptors

Yes, for every WebService server, authorization is a must. I have done a lot of this in my day to day projects. I think it is a good idea to hide it somewhere instead of doing in every logical endpoint.

Interceptor in Spring in a savior. Thanks to AOP, interceptor performs its logic before and after each http request without touching any of the code in controller classes. Take a look at ValidationInterceptor and ExecutionInterceptor and feel how they work.You can also add your customized interceptor and register it in MvcConfiguration class.

Database migration tool

A good practise of managing database schema is to manage it in your code. This help in several ways including:

  • deployment to different environments
  • writing integration tests

Spring Boot supports Liquidbase and Flyway by default. The reason I choose liquidbase is because the flexibility of managing database schema. I use YAML for schema file as it is database agnostic, allowing me the use the same schema file in production and integration test. Even better, if for same reasons, I want to switch MySQL to ProgresSQL or vice versa, I don't need to update any of these schema files.

Spring JPA

Just a easy way to handle database operation. Pretty common requirements in web server, I believe.

Exception handling

Exception handling is another common requirement in not just web server but all kinds of applications. Spring Boot(MVC) takes care of most of the heavy lifting already. Meaning that, it deals with most of the exception it generally you can meet with its framework. But I want to add some specific to my application, eg: validation exception. I added a GlobalExceptionHandler. It saves those exceptions that I didn't think of which I can later revisit. Furthermore, it catches validation exception and returns a proper http status code in response.

Monitoring

Already enabled Spring Actuator. Need to read more in the doc to find out how it works.

web-skeleton's People

Contributors

jiayu avatar

Watchers

 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.