http.d.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /// <reference path="../auto.d.ts" />
  2. declare namespace http {
  3. interface HttpRequestOptions {
  4. header: { [key: string]: string },
  5. method: 'GET' | 'POST' | 'PUT' | 'DELET' | 'PATCH';
  6. contentType: string;
  7. body: string | string[] | files.byte[]
  8. }
  9. interface Request {
  10. }
  11. interface Response {
  12. statusCode: number;
  13. statusMessage: string;
  14. headers: { [key: string]: string };
  15. body: ResponseBody;
  16. request: Request;
  17. url: string;
  18. method: 'GET' | 'POST' | 'PUT' | 'DELET' | 'PATCH';
  19. }
  20. interface ResponseBody {
  21. bytes(): files.byte[];
  22. string(): string;
  23. json(): object;
  24. contentType: string;
  25. }
  26. function get(url: string, options?: HttpRequestOptions, callback?: (resp: Response) => void): Response;
  27. function post(url: string, data: object, options?: HttpRequestOptions, callback?: (resp: Response) => void): Response;
  28. function postJson(url: string, data?: object, options?: HttpRequestOptions, callback?: (resp: Response) => void): Response;
  29. interface RequestMultipartBody {
  30. file: ReadableTextFile | [string, string] | [string, string, string];
  31. }
  32. function postMultipart(url: string, files: RequestMultipartBody, options?: HttpRequestOptions, callback?: (resp: Response) => void): void;
  33. function postMultipart(url: string, files: { [key: string]: string } & RequestMultipartBody, options?: HttpRequestOptions, callback?: (resp: Response) => void): void;
  34. function request(url: string, options?: HttpRequestOptions, callback?: (resp: Response) => void): void;
  35. }