{"id":23127539,"url":"https://github.com/anytv/cuddle","last_synced_at":"2025-08-17T05:31:01.851Z","repository":{"id":21144274,"uuid":"24446554","full_name":"anyTV/cuddle","owner":"anyTV","description":"Cuddle","archived":false,"fork":false,"pushed_at":"2019-07-16T08:39:17.000Z","size":107,"stargazers_count":5,"open_issues_count":1,"forks_count":3,"subscribers_count":21,"default_branch":"master","last_synced_at":"2024-12-09T19:57:22.842Z","etag":null,"topics":["http","javascript","node","rest-api"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anyTV.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}},"created_at":"2014-09-25T06:36:32.000Z","updated_at":"2023-03-10T11:53:32.000Z","dependencies_parsed_at":"2022-07-27T01:47:05.911Z","dependency_job_id":null,"html_url":"https://github.com/anyTV/cuddle","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/anyTV%2Fcuddle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anyTV%2Fcuddle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anyTV%2Fcuddle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anyTV%2Fcuddle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anyTV","download_url":"https://codeload.github.com/anyTV/cuddle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230091585,"owners_count":18171528,"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":["http","javascript","node","rest-api"],"created_at":"2024-12-17T09:13:52.971Z","updated_at":"2024-12-17T09:13:53.593Z","avatar_url":"https://github.com/anyTV.png","language":"JavaScript","readme":"# Cuddle\n\n[![Build Status](https://travis-ci.org/ravenjohn/cuddle.svg?branch=master)](https://travis-ci.org/ravenjohn/cuddle)\n[![NPM version](https://img.shields.io/npm/v/cuddle.svg)](https://www.npmjs.com/package/cuddle)\n\n\nCuddle is a minimal, chainable, retryable and \"readability first\" node http client. It's built to use for calling third-party APIs. Just what you need.\n\n```sh\nnpm i cuddle@latest -S\n```\n\n## Use Cases\n\n### Important notes\n- Status code \u003c 200 or \u003e= 300 will be classifed as an error.\n- Request will not fire unless `.then` or `.end` is called\n\n\n\n### Simple\n```js\nconst cudl = require('cuddle');\n\ncudl.post\n    .to('http://localhost:8082/api/user/1')\n    .set_header('Authorization', 'Token sampletoken')\n    .send({\n        username: 'rvnjl',\n        sex: 'male'\n    })\n    .then((err, result) =\u003e {\n\n        if (err) {\n            //handle error\n        }\n\n        console.log(result);\n    });\n```\n\n\n### Promise:\n```js\nconst cudl = require('cuddle');\n\ncudl.post\n    .to('http://localhost:8082/api/user/1')\n    .set_header('Authorization', 'Token sampletoken')\n    .send({\n        username: 'rvnjl',\n        sex: 'male'\n    })\n    .promise()\n    .then(success)\n    .catch(fail);\n```\n\n\n### Using with generators:\n```js\nconst cudl = require('cuddle');\nconst co = require('co');\n\nfunction* foo () {\n    let user = yield cudl.get\n        .to('http://localhost:8082/api/user/1')\n        .set_header('Authorization', 'Token sampletoken')\n        .promise();\n\n    console.log(user);\n}\n\nco(foo);\n```\n\n### Throttling requests\n```js\n// will only let 50 concurrent requests\ncudl.throttle(50);\n```\n\n\n### Easy scoping through args:\n```js\nconst cudl = require('cuddle');\n\nfunction foo () {\n    const users = [\n        {id: 1, name: 'jeff'},\n        {id: 2, name: 'jenny'},\n        {id: 3, name: 'julius'}\n    ];\n\n    users.forEach(user =\u003e {\n        cudl.get\n            .to('http://localhost:8082/api/user/' + user.id)\n            .args(user)\n            //.max_retry(10)    // to set the number of retries\n            //.debug()          // to log all\n            //.logger(winston)  // to replace the logger (default is console)\n            .then(bar);\n    });\n}\n\nfunction bar (err, result, request, [user]) {\n\n    if (err) {\n        // cuddle will return a different error after reaching maximum retries\n        if (err.code \u003e= 500) {\n            return request.retry();\n        }\n\n        console.error('Error with user ' + user.id + request);\n        return;\n    }\n\n    user.more_info = result;\n\n    // ...\n}\n\nfoo();\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanytv%2Fcuddle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanytv%2Fcuddle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanytv%2Fcuddle/lists"}