{"id":18489111,"url":"https://github.com/hachreak/limitless","last_synced_at":"2025-04-08T21:30:41.432Z","repository":{"id":139147267,"uuid":"71537374","full_name":"hachreak/limitless","owner":"hachreak","description":"An OTP application to integrate a rate-limiter in your application.","archived":false,"fork":false,"pushed_at":"2017-05-16T18:38:57.000Z","size":62,"stargazers_count":16,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-23T18:06:36.596Z","etag":null,"topics":["erlang","erlang-libraries","erlang-library","minidb","mongodb","otp-application","rate-limiter","rate-limiting","rate-limits","rest","rest-api"],"latest_commit_sha":null,"homepage":"https://github.com/hachreak/limitless","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hachreak.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-21T06:42:32.000Z","updated_at":"2019-07-22T18:03:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"d06f7369-4e6e-4a71-9eea-6f7938d16c75","html_url":"https://github.com/hachreak/limitless","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hachreak%2Flimitless","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hachreak%2Flimitless/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hachreak%2Flimitless/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hachreak%2Flimitless/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hachreak","download_url":"https://codeload.github.com/hachreak/limitless/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247931026,"owners_count":21020152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["erlang","erlang-libraries","erlang-library","minidb","mongodb","otp-application","rate-limiter","rate-limiting","rate-limits","rest","rest-api"],"created_at":"2024-11-06T12:55:18.322Z","updated_at":"2025-04-08T21:30:41.427Z","avatar_url":"https://github.com/hachreak.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"limitless\n=========\n\n[![Build Status](https://travis-ci.org/hachreak/limitless.svg?branch=master)](https://travis-ci.org/hachreak/limitless)\n\nLimitless is a lightweight, generic library for Erlang to quickly integrate a\nrate-limiter inside your application.\n\nExample\n-------\n\nSee `examples` directory to see how use the library with the `mongodb` backend.\n\nConfiguration\n-------------\n\nAdd `limitless` to your `rebar.config` deps:\n\n```erlang\n{deps,\n [\n  {limitless, \"\",\n   {git, \"https://github.com/rpt/limitless.git\",\n    {tag, \"v1.1.0\"}}}\n ]}.\n```\n\nRemember to add also the libraries needed by the specific backend (in the\nmongodb example: `uuid`, `mongopool`).\n\nAdd a configuration for specify which backend are you using and which kind\nof limits are you imposing.\n\nIn this example we define that every request of type `token` will be controlled\nby two different limits:\n\n 1. The first limit is 1000 req/day\n 2. The other limit is 100 req/15min\n\n```erlang\n[\n  {limitless, [\n    {backend, [\n      % specify the backend to use\n      {name, limitless_backend_mongopool},\n      % and the backend configuration\n      {config, [\n        {table, limitless},\n        {pool, mymongopool}\n      ]}\n    ]},\n    {limits, [\n      {token, [\n        [\n          % max 1000 req/day\n          {type, \u003c\u003c\"Token-Daily\"\u003e\u003e},\n          {frequency, 86400}, % 1 day = 3600 * 24h\n          {requests, 1000}\n        ],\n        [\n          % max 100 req/15min\n          {type, \u003c\u003c\"Token-15min\"\u003e\u003e},\n          {frequency, 900}, % 15 min = 60 * 15\n          {requests, 100}\n        ]\n      ]}\n    ]}\n  ]}\n]\n```\n\nNote: in the configuration there is also a term `mongopool` to complete the\nbackend configuration.\n\nOn the application running, when a new object `token` we'll be created, also\nshould be registered in the limits lists with:\n\n```erlang\n{ok, Ctx} = limitless:init().\nlimitless:setup(RequestToken, token, ctx).\n```\n\nIn this way, every time you receive a request from a token `RequestToken`,\nyou be able to check if it reached any of its limits\n(in the example: 1000 req/day and 100 req/15min):\n\n```erlang\n{Result, ConsumedTokens, InfoTokens} = limitless:is_reached(\n                                                [RequestToken], LimitlessCtx)\n```\n\nIf `Result` is `true`, it means that at least one limit is reached\n(see `ConsumedTokens` to know which one).\n\nThe `InfoTokens` are useful information to build a table about the current\nsituation.\n\nIn the example, it's used to build the HTTP relative headers:\n\n```erlang\nReq2 = limitless_cowboy_utils:set_rate_limiter_headers(InfoTokens, Req),\n```\n\nIt'll add the following headers to the `cowboy` response:\n\n```\nX-RateLimit-Token-Daily-Limit: 1000\nX-RateLimit-Token-Daily-Remaining: 1000\nX-RateLimit-Token-Daily-Reset: 86250\nX-RateLimit-Token-15min-Limit: 100\nX-RateLimit-Token-15min-Remaining: 100\nX-RateLimit-Token-15min-Reset: 750\n```\n\nStatus\n------\n\nStable release.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhachreak%2Flimitless","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhachreak%2Flimitless","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhachreak%2Flimitless/lists"}