index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. `use strict`
  2. const Request = require('./lib/Request');
  3. /**
  4. * Send a get request
  5. * @return a @Request object
  6. * @param path is the url endpoint
  7. * @param headers of the request
  8. * @param callback contains (error, body, status, headers)
  9. */
  10. function get(path, headers, callback) {
  11. const request = new Request();
  12. request.createRequest(path, "GET", null, headers, callback);
  13. request.sendRequest();
  14. return request;
  15. }
  16. /**
  17. * Send a post request
  18. * @return a @Request object
  19. * @param path is the url endpoint
  20. * @param headers of the request
  21. * @param callback contains (error, body, status, headers)
  22. * @param data a JSON Object or a string
  23. */
  24. function post(path, data, headers, callback) {
  25. const request = new Request();
  26. request.createRequest(path, "POST", data, headers, callback);
  27. request.sendRequest();
  28. return request;
  29. }
  30. /**
  31. * Send a post request
  32. * @return a @Request object
  33. * @param path is the url endpoint
  34. * @param headers of the request
  35. * @param callback contains (error, body, status, headers)
  36. * @param data a JSON Object or a string
  37. * @param requestOptions a JSON Object or a string
  38. */
  39. function request(options, callback) {
  40. const request = new Request();
  41. request.createRequest(options.url, options.method, options.data || {}, options.headers || {}, options.requestOptions, callback);
  42. request.setCookies(options.Cookies);
  43. request.sendRequest();
  44. return request;
  45. }
  46. module.exports = {
  47. get,
  48. request,
  49. post
  50. };