feat: Support body in GET API requests (#7127)
* WIP
* Refactoring HTTP Method & Content Type to be objects instead of arrays
TODO:
1. Set the default content-type for Get request to "None". Currently, it's raw
2. For None content-type, don't send the body field in the API request
* Almost working implementation for the None type
Currently, the body still gets sent in non-GET requests even if the None tab is selected.
* Adding object.freeze to prevent any modifications to HTTP_METHOD_ENUM
* WIP: Using enum & const for ts autocomplete
* working implementation for NONE type, apiContentType prop added to API actions
* WIP
* Refactoring HTTP Method & Content Type to be objects instead of arrays
TODO:
1. Set the default content-type for Get request to "None". Currently, it's raw
2. For None content-type, don't send the body field in the API request
* Almost working implementation for the None type
Currently, the body still gets sent in non-GET requests even if the None tab is selected.
* Adding object.freeze to prevent any modifications to HTTP_METHOD_ENUM
* WIP: Using enum & const for ts autocomplete
* working implementation for NONE type, apiContentType prop added to API actions
* adds apiContentType to actionConfiguration.formData object
* Handling apiContentType property in Rest API formData
* change apiContentType when user types content-type value and switches http method
* makes api editor as similar as possible to postman, project postman.
* Correcting the import in ApiEditorConstants
* Resolved all merge conflicts
* replay DSL functtionality
* removes unneccessary files from worker
* Fixes type declarations, naming e.t.c.
* fix server side merge conflicts
* fix client side merge conflicts
* fix failing cypress tests
Co-authored-by: Irongade <adeoluayangade@yahoo.com>
Co-authored-by: Ayangade Adeoluwa <37867493+Irongade@users.noreply.github.com>
2022-02-15 11:13:48 +00:00
|
|
|
/**
|
|
|
|
|
* This function updates the header at a given index.
|
|
|
|
|
* If headerIndexToUpdate is -1, i.e the header we are looking for is not present, then
|
|
|
|
|
* update the header key-value pair in the first non-empty row
|
|
|
|
|
* @param headers
|
|
|
|
|
* @param headerIndexToUpdate
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
export const getIndextoUpdate = (headers: any, headerIndexToUpdate: number) => {
|
2021-03-23 09:44:44 +00:00
|
|
|
const firstEmptyHeaderRowIndex: number = headers.findIndex(
|
|
|
|
|
(element: { key: string; value: string }) =>
|
|
|
|
|
element && element.key === "" && element.value === "",
|
|
|
|
|
);
|
|
|
|
|
const newHeaderIndex =
|
|
|
|
|
firstEmptyHeaderRowIndex > -1 ? firstEmptyHeaderRowIndex : headers.length;
|
|
|
|
|
const indexToUpdate =
|
feat: Support body in GET API requests (#7127)
* WIP
* Refactoring HTTP Method & Content Type to be objects instead of arrays
TODO:
1. Set the default content-type for Get request to "None". Currently, it's raw
2. For None content-type, don't send the body field in the API request
* Almost working implementation for the None type
Currently, the body still gets sent in non-GET requests even if the None tab is selected.
* Adding object.freeze to prevent any modifications to HTTP_METHOD_ENUM
* WIP: Using enum & const for ts autocomplete
* working implementation for NONE type, apiContentType prop added to API actions
* WIP
* Refactoring HTTP Method & Content Type to be objects instead of arrays
TODO:
1. Set the default content-type for Get request to "None". Currently, it's raw
2. For None content-type, don't send the body field in the API request
* Almost working implementation for the None type
Currently, the body still gets sent in non-GET requests even if the None tab is selected.
* Adding object.freeze to prevent any modifications to HTTP_METHOD_ENUM
* WIP: Using enum & const for ts autocomplete
* working implementation for NONE type, apiContentType prop added to API actions
* adds apiContentType to actionConfiguration.formData object
* Handling apiContentType property in Rest API formData
* change apiContentType when user types content-type value and switches http method
* makes api editor as similar as possible to postman, project postman.
* Correcting the import in ApiEditorConstants
* Resolved all merge conflicts
* replay DSL functtionality
* removes unneccessary files from worker
* Fixes type declarations, naming e.t.c.
* fix server side merge conflicts
* fix client side merge conflicts
* fix failing cypress tests
Co-authored-by: Irongade <adeoluayangade@yahoo.com>
Co-authored-by: Ayangade Adeoluwa <37867493+Irongade@users.noreply.github.com>
2022-02-15 11:13:48 +00:00
|
|
|
headerIndexToUpdate > -1 ? headerIndexToUpdate : newHeaderIndex;
|
2021-03-23 09:44:44 +00:00
|
|
|
return indexToUpdate;
|
|
|
|
|
};
|
2021-06-03 04:58:18 +00:00
|
|
|
|
|
|
|
|
export const queryParamsRegEx = /([\s\S]*?)(\?(?![^{]*})[\s\S]*)?$/;
|
|
|
|
|
|
|
|
|
|
export function parseUrlForQueryParams(url: string) {
|
|
|
|
|
const padQueryParams = { key: "", value: "" };
|
|
|
|
|
let params = Array(2).fill(padQueryParams);
|
|
|
|
|
const matchGroup = url.match(queryParamsRegEx) || [];
|
|
|
|
|
const parsedUrlWithQueryParams = matchGroup[2] || "";
|
|
|
|
|
if (parsedUrlWithQueryParams.indexOf("?") > -1) {
|
|
|
|
|
const paramsString = parsedUrlWithQueryParams.substr(
|
|
|
|
|
parsedUrlWithQueryParams.indexOf("?") + 1,
|
|
|
|
|
);
|
|
|
|
|
params = paramsString.split("&").map((p) => {
|
|
|
|
|
const firstEqualPos = p.indexOf("=");
|
|
|
|
|
const keyValue =
|
|
|
|
|
firstEqualPos > -1
|
|
|
|
|
? [p.substring(0, firstEqualPos), p.substring(firstEqualPos + 1)]
|
|
|
|
|
: [];
|
|
|
|
|
return { key: keyValue[0] || "", value: keyValue[1] || "" };
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return params;
|
|
|
|
|
}
|