Giter Club home page Giter Club logo

hashids-spring-boot-starter's Introduction

Hashids Spring Boot Starter

Maven Central

  • Provides a bean for Hashids from https://github.com/10cella/hashids-java
  • Allows customizing the properties of Hashids via Spring properties (hashids.salt, hashids.min-hash-length and hashids.alphabet)
  • Automatically decodes Spring request parameters
  • Automatically encodes/decodes values with jackson

Usage

Add the dependency

This library is available Maven Central. If using Maven, add the following dependency to your pom.xml:

<dependency>
  <groupId>systems.fehn</groupId>
  <artifactId>hashids-spring-boot-starter</artifactId>
  <version>${version}</version>
</dependency>

If using Gradle, add the following dependency:

implementation 'systems.fehn:hashids-spring-boot-starter:${version}'

If using Gradle with the Kotlin DSL, add the following dependency:

implementation("systems.fehn:hashids-spring-boot-starter:${version}")

Configuration

Customize how the hashids object is created by using the Spring properties:

  • hashids.salt
  • hashids.min-hash-length
  • hashids.alphabet

Hashids bean

@Autowire an org.hashids.Hashids bean into your Spring components. E.g.:

@Controller
public class UserController {
    private final Hashids hashids;

    public UserController(final Hashids hashids) {
        this.hashids = hashids;
    }
}

@Hashids annotation

Model fields

Alternatively, you can annotate fields in your models with @systems.fehn.boot.starter.hashids.Hashids:

public class UserModel {
    @Hashids
    public long id;
    public String name;
}

Now the user's id will be automatically encoded and decoded with the Hashids bean.

@Hashids can be applied to types int, Integer, long, Long and arrays of these types.

You can customize all settings for each annotation (they are optional and default to the value of the corresponding property):

public class UserModel {
    @Hashids(salt = "abc", minHashLength = 8, alphabet = "abcdefghijklmnopqrstuvwxyz")
    public long id;
    public String name;
}

Controller parameters

Request parameters of controller methods can be annotated in the same fashion.

hashids-spring-boot-starter's People

Contributors

fehnomenal 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.