Skip to content

feat: show full request url in RunIt response #906

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 18 additions & 3 deletions packages/run-it/src/RunIt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
useTabs,
} from '@looker/components'
import type { ApiModel, IMethod } from '@looker/sdk-codegen'
import type { BaseTransport } from '@looker/sdk-rtl'
import type { ResponseContent } from './components'
import {
RequestForm,
Expand All @@ -51,11 +52,11 @@ import {
initRequestContent,
createRequestParams,
runRequest,
pathify,
sdkNeedsConfig,
prepareInputs,
sdkNeedsAuth,
createInputs,
requestUrl,
} from './utils'
import type { RunItSetter } from '.'
import { runItNoSet, RunItContext } from '.'
Expand Down Expand Up @@ -126,6 +127,7 @@ export const RunIt: FC<RunItProps> = ({
initRequestContent(configurator, inputs)
)
const [activePathParams, setActivePathParams] = useState({})
const [activeQueryParams, setActiveQueryParams] = useState({})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: given how tightly coupled path and query params are and that they are always updated together, consider merging these into one state object, activeRequestParams. Resultant state updates can then happen in one call.

const [loading, setLoading] = useState(false)
const [responseContent, setResponseContent] =
useState<ResponseContent>(undefined)
Expand Down Expand Up @@ -173,6 +175,7 @@ export const RunIt: FC<RunItProps> = ({
}
}
setActivePathParams(pathParams)
setActiveQueryParams(queryParams)
tabs.onSelectTab(1)
if (sdk) {
setLoading(true)
Expand Down Expand Up @@ -240,12 +243,24 @@ export const RunIt: FC<RunItProps> = ({
<TabPanel key="response">
<Loading
loading={loading}
message={`${httpMethod} ${pathify(endpoint, activePathParams)}`}
message={`${httpMethod} ${requestUrl(
sdk.authSession.transport as BaseTransport,
basePath,
endpoint,
activePathParams,
activeQueryParams
)}`}
/>
<ResponseExplorer
response={responseContent}
verb={httpMethod}
path={pathify(endpoint, activePathParams)}
path={requestUrl(
sdk.authSession.transport as BaseTransport,
basePath,
endpoint,
activePathParams,
activeQueryParams
)}
/>
</TabPanel>
<TabPanel key="makeTheCall">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ interface ResponseExplorerProps {
* Explore the raw response from an HTTP request
* @param response IRawResponse values
* @param verb HTTP method
* @param path Path of request
* @param path Full path of request, including query string
* @constructor
*/
export const ResponseExplorer: FC<ResponseExplorerProps> = ({
Expand All @@ -145,11 +145,8 @@ export const ResponseExplorer: FC<ResponseExplorerProps> = ({
{!response && <DarkSpan>No response was received</DarkSpan>}
{response && (
<>
<RunItHeading as="h4">
{`${verb || ''} ${path || ''} (${response.statusCode}: ${
response.statusMessage
})`}
</RunItHeading>
<RunItHeading as="h4">{`${verb || ''} ${path || ''}`}</RunItHeading>
<DarkSpan>{`${response.statusCode}: ${response.statusMessage}`}</DarkSpan>
<CollapserCard
divider={false}
heading={`Body (${getBodySize(response)})`}
Expand Down
22 changes: 21 additions & 1 deletion packages/run-it/src/utils/requestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

*/

import type { IAPIMethods, IRawResponse } from '@looker/sdk-rtl'
import type { BaseTransport, IAPIMethods, IRawResponse } from '@looker/sdk-rtl'
import cloneDeep from 'lodash/cloneDeep'
import { isEmpty } from 'lodash'
import type { IApiModel, IMethod, IType } from '@looker/sdk-codegen'
Expand Down Expand Up @@ -172,6 +172,26 @@ export const createRequestParams = (
return [pathParams, queryParams, body]
}

/**
* Construct the full request URL
* @param transport to get server's host url
* @param path to REST server
* @param endpoint REST endpoint
* @param pathParams path parameters
* @param queryParams collection
*/
export const requestUrl = (
transport: BaseTransport,
path: string,
endpoint: string,
pathParams: RunItValues,
queryParams?: RunItValues
) => {
path = `${path}${pathify(endpoint, pathParams)}`
const url = transport.makeUrl(path, transport.options, queryParams)
return url
}

/**
* Makes an http request using the SDK browser transport rawRequest method
* @param sdk functional SDK that supports rawRequest via its transport
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-node/src/nodeTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export type RequestOptions = rq.RequiredUriUrl &
rq.OptionsWithUrl

export class NodeTransport extends BaseTransport {
constructor(protected readonly options: ITransportSettings) {
constructor(public readonly options: ITransportSettings) {
super(options)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-rtl/src/baseTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import type {
} from './transport'

export abstract class BaseTransport implements ITransport {
protected constructor(protected readonly options: ITransportSettings) {
protected constructor(readonly options: ITransportSettings) {
this.options = options
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-rtl/src/browserTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class BrowserCryptoHash implements ICryptoHash {
}

export class BrowserTransport extends BaseTransport {
constructor(protected readonly options: ITransportSettings) {
constructor(public readonly options: ITransportSettings) {
super(options)
}

Expand Down