feat: support for sending xml and text request body (resolves #10)

This commit is contained in:
Anoop M D
2022-10-02 04:58:43 +05:30
parent 6e926f0ba6
commit 7f0f496bb4
8 changed files with 156 additions and 18 deletions

View File

@@ -7,11 +7,11 @@ import StyledWrapper from './StyledWrapper';
const RequestBody = ({item, collection}) => {
const dispatch = useDispatch();
const bodyContent = item.draft ? get(item, 'draft.request.body.content') : get(item, 'request.body.content');
const body = item.draft ? get(item, 'draft.request.body') : get(item, 'request.body');
const bodyMode = item.draft ? get(item, 'draft.request.body.mode') : get(item, 'request.body.mode');
const onEdit = (value) => {
dispatch(updateRequestBody({
mode: 'json',
content: value,
itemUid: item.uid,
collectionUid: collection.uid,
@@ -19,11 +19,37 @@ const RequestBody = ({item, collection}) => {
};
const onRun = () => dispatch(sendRequest(item, collection.uid));;
const onSave = () => dispatch(saveRequest(item.uid, collection.uid));;
const onSave = () => dispatch(saveRequest(item.uid, collection.uid));
if(['json', 'xml', 'text'].includes(bodyMode)) {
let codeMirrorMode = {
json: 'application/ld+json',
text: 'application/text',
xml: 'application/xml'
};
let bodyContent = {
json: body.json,
text: body.text,
xml: body.xml
};
return(
<StyledWrapper className="w-full">
<CodeEditor
value={bodyContent[bodyMode] || ''}
onEdit={onEdit}
onRun={onRun}
onSave={onSave}
mode={codeMirrorMode[bodyMode]}
/>
</StyledWrapper>
);
}
return(
<StyledWrapper className="w-full">
<CodeEditor value={bodyContent || ''} onEdit={onEdit} onRun={onRun} onSave={onSave}/>
No Body
</StyledWrapper>
);
};