Skip to content

Commit 7f48a16

Browse files
committed
feat: show full request url in RunIt response
The Response tab now shows the full request URL, not including the request body (which can't be included in this scenario)
1 parent 2f10dd3 commit 7f48a16

File tree

6 files changed

+45
-13
lines changed

6 files changed

+45
-13
lines changed

packages/run-it/src/RunIt.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
useTabs,
3636
} from '@looker/components'
3737
import type { ApiModel, IMethod } from '@looker/sdk-codegen'
38+
import type { BaseTransport } from '@looker/sdk-rtl'
3839
import type { ResponseContent } from './components'
3940
import {
4041
RequestForm,
@@ -51,11 +52,11 @@ import {
5152
initRequestContent,
5253
createRequestParams,
5354
runRequest,
54-
pathify,
5555
sdkNeedsConfig,
5656
prepareInputs,
5757
sdkNeedsAuth,
5858
createInputs,
59+
requestUrl,
5960
} from './utils'
6061
import type { RunItSetter } from '.'
6162
import { runItNoSet, RunItContext } from '.'
@@ -126,6 +127,7 @@ export const RunIt: FC<RunItProps> = ({
126127
initRequestContent(configurator, inputs)
127128
)
128129
const [activePathParams, setActivePathParams] = useState({})
130+
const [activeQueryParams, setActiveQueryParams] = useState({})
129131
const [loading, setLoading] = useState(false)
130132
const [responseContent, setResponseContent] =
131133
useState<ResponseContent>(undefined)
@@ -173,6 +175,7 @@ export const RunIt: FC<RunItProps> = ({
173175
}
174176
}
175177
setActivePathParams(pathParams)
178+
setActiveQueryParams(queryParams)
176179
tabs.onSelectTab(1)
177180
if (sdk) {
178181
setLoading(true)
@@ -240,12 +243,24 @@ export const RunIt: FC<RunItProps> = ({
240243
<TabPanel key="response">
241244
<Loading
242245
loading={loading}
243-
message={`${httpMethod} ${pathify(endpoint, activePathParams)}`}
246+
message={`${httpMethod} ${requestUrl(
247+
sdk.authSession.transport as BaseTransport,
248+
basePath,
249+
endpoint,
250+
activePathParams,
251+
activeQueryParams
252+
)}`}
244253
/>
245254
<ResponseExplorer
246255
response={responseContent}
247256
verb={httpMethod}
248-
path={pathify(endpoint, activePathParams)}
257+
path={requestUrl(
258+
sdk.authSession.transport as BaseTransport,
259+
basePath,
260+
endpoint,
261+
activePathParams,
262+
activeQueryParams
263+
)}
249264
/>
250265
</TabPanel>
251266
<TabPanel key="makeTheCall">

packages/run-it/src/components/ResponseExplorer/ResponseExplorer.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ interface ResponseExplorerProps {
129129
* Explore the raw response from an HTTP request
130130
* @param response IRawResponse values
131131
* @param verb HTTP method
132-
* @param path Path of request
132+
* @param path Full path of request, including query string
133133
* @constructor
134134
*/
135135
export const ResponseExplorer: FC<ResponseExplorerProps> = ({
@@ -145,11 +145,8 @@ export const ResponseExplorer: FC<ResponseExplorerProps> = ({
145145
{!response && <DarkSpan>No response was received</DarkSpan>}
146146
{response && (
147147
<>
148-
<RunItHeading as="h4">
149-
{`${verb || ''} ${path || ''} (${response.statusCode}: ${
150-
response.statusMessage
151-
})`}
152-
</RunItHeading>
148+
<RunItHeading as="h4">{`${verb || ''} ${path || ''}`}</RunItHeading>
149+
<DarkSpan>{`${response.statusCode}: ${response.statusMessage}`}</DarkSpan>
153150
<CollapserCard
154151
divider={false}
155152
heading={`Body (${getBodySize(response)})`}

packages/run-it/src/utils/requestUtils.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
*/
2626

27-
import type { IAPIMethods, IRawResponse } from '@looker/sdk-rtl'
27+
import type { BaseTransport, IAPIMethods, IRawResponse } from '@looker/sdk-rtl'
2828
import cloneDeep from 'lodash/cloneDeep'
2929
import { isEmpty } from 'lodash'
3030
import type { IApiModel, IMethod, IType } from '@looker/sdk-codegen'
@@ -172,6 +172,26 @@ export const createRequestParams = (
172172
return [pathParams, queryParams, body]
173173
}
174174

175+
/**
176+
* Construct the full request URL
177+
* @param transport to get server's host url
178+
* @param path to REST server
179+
* @param endpoint REST endpoint
180+
* @param pathParams path parameters
181+
* @param queryParams collection
182+
*/
183+
export const requestUrl = (
184+
transport: BaseTransport,
185+
path: string,
186+
endpoint: string,
187+
pathParams: RunItValues,
188+
queryParams?: RunItValues
189+
) => {
190+
path = `${path}${pathify(endpoint, pathParams)}`
191+
const url = transport.makeUrl(path, transport.options, queryParams)
192+
return url
193+
}
194+
175195
/**
176196
* Makes an http request using the SDK browser transport rawRequest method
177197
* @param sdk functional SDK that supports rawRequest via its transport

packages/sdk-node/src/nodeTransport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export type RequestOptions = rq.RequiredUriUrl &
8383
rq.OptionsWithUrl
8484

8585
export class NodeTransport extends BaseTransport {
86-
constructor(protected readonly options: ITransportSettings) {
86+
constructor(public readonly options: ITransportSettings) {
8787
super(options)
8888
}
8989

packages/sdk-rtl/src/baseTransport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import type {
3838
} from './transport'
3939

4040
export abstract class BaseTransport implements ITransport {
41-
protected constructor(protected readonly options: ITransportSettings) {
41+
protected constructor(readonly options: ITransportSettings) {
4242
this.options = options
4343
}
4444

packages/sdk-rtl/src/browserTransport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class BrowserCryptoHash implements ICryptoHash {
7777
}
7878

7979
export class BrowserTransport extends BaseTransport {
80-
constructor(protected readonly options: ITransportSettings) {
80+
constructor(public readonly options: ITransportSettings) {
8181
super(options)
8282
}
8383

0 commit comments

Comments
 (0)