2 |
3 |
8 | Simple, open-source, powerful tools for modern serverless applications
9 |
12 | All tools are easily self-hostable, fully typed, and designed for serverless-first environments. 13 |
14 | 15 | ## Authentication 16 | [Follow this guide to authenticate if using our managed service.](https://borrow.dev/docs/limiter/quick-start#authentication) 17 | 18 | ## Documentation 19 | [Read the full documentation for Borrow.](https://borrow.dev/docs) 20 | 21 | ## Borrow Limiter 22 | Self-hostable rate limiting API for protecting regular service usage. 23 | 24 | ### Usage 25 | 26 | Let's use the [fixed window](https://borrow.dev/docs/limiter/algorithms#fixed-window) algorithm to rate limit our login endpoint to 10 requests per minute. 27 | 28 | ```javascript 29 | import { borrow } from "@borrowdev/node"; 30 | 31 | const { success, timeLeft } = await borrow.limiter("my-limiter-id", "current-user-id", { 32 | limiters: [{ 33 | maxRequests: 10, 34 | interval: "minute", 35 | type: "fixed", 36 | }] 37 | }); 38 | if (!success) { 39 | return { message: "Rate limit exceeded." + timeLeft !== null ? ` You can try again in ${timeLeft} seconds.` : "" }; 40 | } 41 | ``` 42 | 43 | ### Self host 44 | To self-host the Limiter API, follow the [self-hosting guide](https://borrow.dev/docs/limiter/self-hosting). 45 | 46 | ## Borrow CLI - The Developer Toolkit 47 | 48 | ### Install 49 | ```bash 50 | cargo install borrow-dev 51 | ``` 52 | 53 | ### Start 54 | Borrow Start is a command-line tool that helps you quickly set up common boilerplate code with pre-defined templates and placeholders. 55 | 56 | Templates are downloaded from the [Borrow registry](https://github.com/borrowdev/registry), or you can create your own templates 57 | and refer to them locally by using the `local:` prefix before ``. 58 | 59 | #### Usage 60 | ```bash 61 | # Download and install a template 62 | borrow start new -t -o