-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/rate limit using bucket4j (#3)
* Rate Limit Spring Boot REST API using Bucket4j * Rate Limit Spring Boot REST API using Bucket4j * Added Spring security examples
- Loading branch information
Showing
108 changed files
with
2,135 additions
and
346 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
movies-rest-api-monogdb/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
spring.data.mongodb.uri=mongodb://localhost:27017/movies?locale=en | ||
spring.data.mongodb.username= | ||
spring.data.mongodb.password= | ||
spring.data.mongodb.username=root | ||
spring.data.mongodb.password=Passw0rd | ||
|
||
#open API path | ||
springdoc.api-docs.path=/api-docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,65 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<artifactId>ratelimit-api-using-bucket4j</artifactId> | ||
<description>Demo project for Spring Boot</description> | ||
<groupId>com.stacktips</groupId> | ||
<modelVersion>4.0.0</modelVersion> | ||
<name>movies-api</name> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.3.2</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
<groupId>org.springframework.boot</groupId> | ||
<relativePath/> | ||
<version>3.3.2</version> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>com.stacktips</groupId> | ||
<artifactId>springboot-rest-api-monogdb</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>movies-api</name> | ||
<description>Demo project for Spring Boot</description> | ||
<properties> | ||
<java.version>17</java.version> | ||
</properties> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<groupId>org.springframework.boot</groupId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<!-- For java 17+ --> | ||
<dependency> | ||
<groupId>com.bucket4j</groupId> | ||
<artifactId>bucket4j_jdk17-core</artifactId> | ||
<groupId>com.bucket4j</groupId> | ||
<version>8.13.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-mongodb</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<groupId>org.springframework.boot</groupId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<groupId>org.springframework.boot</groupId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<version>5.3.1</version> | ||
<groupId>io.rest-assured</groupId> | ||
<scope>test</scope> | ||
<version>5.3.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>json-path</artifactId> | ||
<version>5.3.1</version> | ||
<groupId>io.rest-assured</groupId> | ||
<scope>test</scope> | ||
<version>5.3.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<groupId>org.projectlombok</groupId> | ||
<scope>annotationProcessor</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
ratelimit-api-using-bucket4j/src/main/java/com/stacktips/movies/MyApiApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.stacktips.movies; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class MyApiApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(MyApiApplication.class, args); | ||
} | ||
|
||
} |
16 changes: 0 additions & 16 deletions
16
...mit-api-using-bucket4j/src/main/java/com/stacktips/movies/api/GlobalExceptionHandler.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
ratelimit-api-using-bucket4j/src/main/java/com/stacktips/movies/api/HelloController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.stacktips.movies.api; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping(value = "/hello", | ||
produces = {MediaType.APPLICATION_JSON_VALUE}) | ||
public class HelloController { | ||
|
||
@GetMapping | ||
public Map<String, String> hello() { | ||
return Collections.singletonMap("hello", "world!"); | ||
} | ||
} |
45 changes: 0 additions & 45 deletions
45
ratelimit-api-using-bucket4j/src/main/java/com/stacktips/movies/api/MoviesController.java
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
ratelimit-api-using-bucket4j/src/main/java/com/stacktips/movies/config/BucketConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.stacktips.movies.config; | ||
|
||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.time.Duration; | ||
import java.util.Map; | ||
|
||
@Data | ||
@Configuration | ||
@ConfigurationProperties(prefix = "rate-limiting") | ||
public class BucketConfig { | ||
|
||
private Map<String, ClientBucketConfig> clients; | ||
|
||
@Data | ||
public static class ClientBucketConfig { | ||
|
||
private int capacity; | ||
private int refillTokens; | ||
private Duration refillDuration; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.