diff options
| author | William Boman <william@redwill.se> | 2022-10-08 15:34:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-08 15:34:20 +0200 |
| commit | 72efedba614355b48109206ecf2cd3e2ce62731d (patch) | |
| tree | 347a95b2d88ef77256c09939e98a3d9fa6b715f5 /lua/mason-registry/api.lua | |
| parent | feat(registry): add pylama linter (#523) (diff) | |
| download | mason-72efedba614355b48109206ecf2cd3e2ce62731d.tar mason-72efedba614355b48109206ecf2cd3e2ce62731d.tar.gz mason-72efedba614355b48109206ecf2cd3e2ce62731d.tar.bz2 mason-72efedba614355b48109206ecf2cd3e2ce62731d.tar.lz mason-72efedba614355b48109206ecf2cd3e2ce62731d.tar.xz mason-72efedba614355b48109206ecf2cd3e2ce62731d.tar.zst mason-72efedba614355b48109206ecf2cd3e2ce62731d.zip | |
feat(registry): add api module (#524)
Diffstat (limited to 'lua/mason-registry/api.lua')
| -rw-r--r-- | lua/mason-registry/api.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lua/mason-registry/api.lua b/lua/mason-registry/api.lua new file mode 100644 index 00000000..1fa01b26 --- /dev/null +++ b/lua/mason-registry/api.lua @@ -0,0 +1,21 @@ +local _ = require "mason-core.functional" +local fetch = require "mason-core.fetch" + +local api = {} + +local stringify_params = _.compose(_.join "&", _.map(_.join "="), _.sort_by(_.head), _.to_pairs) + +---@async +---@param path string +---@param opts { params: table<string, any>? }? +---@return Result # JSON decoded response. +function api.get(path, opts) + if opts and opts.params then + local params = stringify_params(opts.params) + path = ("%s?%s"):format(path, params) + end + -- https://github.com/williamboman/mason-registry-api + return fetch(("https://api.mason-registry.dev%s"):format(path)):map_catching(vim.json.decode) +end + +return api |
