Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Send proper request body type for code snippets #1639

Merged
merged 5 commits into from
Apr 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/app/services/actions/snippet-action-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function getSnippetPending(): any {
export function getSnippet(language: string): Function {
return async (dispatch: Function, getState: Function) => {
const { devxApi, sampleQuery } = getState();

try {
let snippetsUrl = `${devxApi.baseUrl}/api/graphexplorersnippets`;

Expand All @@ -56,13 +57,19 @@ export function getSnippet(language: string): Function {

const requestBody =
sampleQuery.sampleBody &&
Object.keys(sampleQuery.sampleBody).length !== 0 && // check if empty object
sampleQuery.sampleBody.trim() !== ''
Object.keys(sampleQuery.sampleBody).length !== 0
? JSON.stringify(sampleQuery.sampleBody)
: '';

const httpVersion = 'HTTP/1.1';
const host = 'Host: graph.microsoft.com';
const sampleHeaders = 'Content-Type: application/json';

// eslint-disable-next-line max-len
const body = `${sampleQuery.selectedVerb} /${queryVersion}/${requestUrl + search} HTTP/1.1\r\nHost: graph.microsoft.com\r\nContent-Type: application/json\r\n\r\n${requestBody}`;
let body = `${sampleQuery.selectedVerb} /${queryVersion}/${requestUrl + search} ${httpVersion}\r\n${host}\r\n${sampleHeaders}\r\n\r\n`;
if(sampleQuery.selectedVerb !== 'GET'){
body += `${requestBody}`;
}

const options: IRequestOptions = { method, headers, body };
const obj: any = {};
Expand Down