{"id":19670681,"url":"https://github.com/kostastepetes/grab-js","last_synced_at":"2025-10-29T11:44:47.834Z","repository":{"id":219912750,"uuid":"747114339","full_name":"kostastepetes/grab-js","owner":"kostastepetes","description":"🤝 A small (1.8 kB) and comprehensive AJAX Library.","archived":false,"fork":false,"pushed_at":"2024-01-31T11:29:42.000Z","size":87,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-10T03:35:28.628Z","etag":null,"topics":["ajax","ajax-library","http-requests","xhr","xhr-requests"],"latest_commit_sha":null,"homepage":"https://grab-js.netlify.app/","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/kostastepetes.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2024-01-23T09:45:34.000Z","updated_at":"2024-01-30T09:21:14.000Z","dependencies_parsed_at":"2025-01-10T03:35:28.667Z","dependency_job_id":"08cbc843-ff94-4736-a437-783937c13b44","html_url":"https://github.com/kostastepetes/grab-js","commit_stats":null,"previous_names":["kostastepetes/grab-js"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kostastepetes%2Fgrab-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kostastepetes%2Fgrab-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kostastepetes%2Fgrab-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kostastepetes%2Fgrab-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kostastepetes","download_url":"https://codeload.github.com/kostastepetes/grab-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240980842,"owners_count":19888344,"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":["ajax","ajax-library","http-requests","xhr","xhr-requests"],"created_at":"2024-11-11T17:06:53.549Z","updated_at":"2025-10-29T11:44:47.771Z","avatar_url":"https://github.com/kostastepetes.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# grab.js Documentation\r\n\r\n## Introduction\r\n`grab.js` is a lightweight AJAX library that simplifies making XMLHttpRequests in JavaScript. It provides a convenient and chainable interface for configuring and executing AJAX requests with features such as handling headers, enabling CORS, setting timeouts, and more.\r\n\r\n## Current Version\r\n`grab.js` is a currently in BETA v0.1.0.\r\n\r\n## Table of Contents\r\n1. [Initialization](#initialization)\r\n2. [Configuration Methods](#configuration-methods)\r\n    - [perform](#perform)\r\n    - [here](#here)\r\n    - [setData](#setdata)\r\n    - [setHeaders](#setheaders)\r\n    - [enableCors](#enablecors)\r\n    - [error](#error)\r\n    - [abort](#abort)\r\n3. [Request Execution](#request-execution)\r\n    - [done](#done)\r\n4. [Examples](#examples)\r\n\r\n## Initialization\u003ca name=\"initialization\"\u003e\u003c/a\u003e\r\nInclude the `grab.js` script in your HTML file to use it:\r\n```html\r\n\u003cscript src=\"https://cdn.jsdelivr.net/gh/kostastepetes/grab-js/dist/grab.min.js\"\u003e\u003c/script\u003e\r\n```\r\n\r\n## Configuration Methods\u003ca name=\"configuration-methods\"\u003e\u003c/a\u003e\r\n### perform(method, url, async)\r\nSpecify the HTTP method, URL, and asynchronous flag for the request.\r\n```javascript\r\ngrab.perform(\"GET\", \"https://jsonplaceholder.typicode.com/posts\", true);\r\n```\r\n\r\n### here(targetElement, callback)\r\nSet the target HTML element and callback function for the request.\r\n```javascript\r\ngrab.here('HTMLElement', yourCallbackFunction);\r\n```\r\n\r\n### setData(data)\r\nSet the request payload data.\r\n```javascript\r\ngrab.setData(JSON.stringify({ title: 'Post Title', body: 'Post Body', userId: 1 }));\r\n```\r\n\r\n### setHeaders(headers)\r\nSet the headers for the request.\r\n```javascript\r\ngrab.setHeaders({ 'Content-type': 'application/json' });\r\n```\r\n\r\n### enableCors(enable)\r\nEnable or disable Cross-Origin Resource Sharing (CORS) globally for all requests made using the `grab.js` library.\r\n```javascript\r\ngrab.enableCors = true; \r\ngrab.enableCors = false;\r\n```\r\n\r\n### error(callback)\r\nSet a callback function to handle errors during the request.\r\n```javascript\r\ngrab.error(function() {\r\n    console.error('An error occurred during the request.');\r\n});\r\n```\r\n\r\n### abort()\r\nAbort the ongoing request.\r\n```javascript\r\ngrab.abort();\r\n```\r\n\r\n## Request Execution\u003ca name=\"request-execution\"\u003e\u003c/a\u003e\r\n### done()\r\nExecute the configured request.\r\n```javascript\r\ngrab.done();\r\n```\r\n\r\n## Examples\u003ca name=\"examples\"\u003e\u003c/a\u003e\r\n### Specific Header with POST and Custom Content-Type\r\n```javascript\r\nfunction performSpecificHeaderPOST() {\r\n    grab.perform('POST', 'https://jsonplaceholder.typicode.com/posts', true)\r\n        .here('HTMLElement', yourCallbackFunction)\r\n        .setData(JSON.stringify({ title: 'Post Title', body: 'Post Body', userId: 1 }))\r\n        .setHeaders({ 'Content-type': 'application/json' })\r\n        .done();\r\n}\r\n```\r\n\r\n### Multiple Headers\r\n```javascript\r\nfunction performMultipleHeadersPOST() {\r\n    grab.perform('POST', 'https://jsonplaceholder.typicode.com/posts', true)\r\n        .here('HTMLElement', yourCallbackFunction)\r\n        .setData(JSON.stringify({ title: 'Post Title', body: 'Post Body', userId: 1 }))\r\n        .setHeaders({\r\n            'Content-type': 'application/json',\r\n            'Authorization': 'Bearer your_access_token'\r\n        })\r\n        .done();\r\n}\r\n```\r\n\r\n### Specific Header\r\n```javascript\r\nfunction performSpecificHeaderGET() {\r\n    grab.perform('GET', 'https://jsonplaceholder.typicode.com/posts/1', true)\r\n        .here('HTMLElement', yourCallbackFunction)\r\n        .setHeaders({ 'Accept': 'application/json' })\r\n        .done();\r\n}\r\n```\r\n\r\n### All Headers\r\n```javascript\r\nfunction performAllHeadersGET() {\r\n    grab.perform('GET', 'https://jsonplaceholder.typicode.com/posts/1', true)\r\n        .here('HTMLElement', 'all')\r\n        .done();\r\n}\r\n```\r\n\r\n### Aborting the Request\r\n```javascript\r\nfunction performAbort() {\r\n    setTimeout(function() {\r\n        grab.abort(); // Simulate aborting the request after a delay\r\n    }, 2000); // Abort after 2 seconds\r\n}\r\n```\r\n\r\n### Enabling CORS\r\n```javascript\r\nfunction performCORS(enable) {\r\n    grab.enableCors = enable;\r\n    grab.perform('GET', 'https://jsonplaceholder.typicode.com/posts/1', true, enable)\r\n        .here('HTMLElement', yourCallbackFunction)\r\n        .done();\r\n}\r\n```\r\n\r\n### Error Handling\r\n```javascript\r\nfunction performErrorHandling() {\r\n    grab.perform('POST', 'https://jsonplaceholder.typicode.com/posts', true)\r\n        .here('HTMLElement', yourCallbackFunction)\r\n        .setData(JSON.stringify({ title: 'Invalid Post' }))\r\n        .setHeaders({ 'Content-type': 'application/json' })\r\n        .error(function() {\r\n            console.log('Error occurred during the request.');\r\n        })\r\n        .done();\r\n}\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkostastepetes%2Fgrab-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkostastepetes%2Fgrab-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkostastepetes%2Fgrab-js/lists"}