# http-amd **Repository Path**: mirrors_guybedford/http-amd ## Basic Information - **Project Name**: http-amd - **Description**: A minimal HTTP library for RequireJS with a single API for both the browser and server, allowing for cross-compatible code - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-24 - **Last Updated**: 2026-04-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README http-AMD ==== A RequireJS module to allow for HTTP services and calls both on the client and server side. Additionally, comes with a basic JSON request API for sending and receiving JSON both client and server side. When on the client, an AJAX library is used. When on the server, the NodeJS http library is used, both with the same API. _If Rhino support is needed, please post a feature request / pull request._ Install --- ``` volo add guybedford/http-amd ``` If not using Volo, ensure you download [RequireIS](https://github.com/guybedford/require-is) as well. This allows the conditional server / client code loading. ```javascript { map: { '*': { 'http': 'http-amd/http' } } } ``` API --- #### HTTP API ```javascript http.send(method, url, headers, data, callback, errback); http.get(url, headers, callback, errback); http.post(url, headers, data, callback, errback); http.put(url, headers, data, callback, errback); http.del(url, headers, callback, errback); data is a string callback has the response string as its argument headers, callback and errback are all optional arguments. ``` #### JSON API Located at `'http-amd/json'`. Automatically includes the headers: `Content-Type: application/json; charset=utf-8` `accept: application/json` ```javascript json.send(method, url, headers, data, callback, errback); json.get(url, headers, callback, errback); json.post(url, headers, data, callback, errback); json.put(url, headers, data, callback, errback); json.del(url, headers, callback, errback); data is an object callback has the response JSON as its argument (if not a JSON response, an error is thrown) headers, callback and errback are all optional arguments. ``` Example --- ```javascript define(['http-amd/http'], function(http) { http.get('local-service/api', function(response) { //do something with the response }, function(err) { //do something with the error }); }); ```