本文整理汇总了TypeScript中client/request.request类的典型用法代码示例。如果您正苦于以下问题:TypeScript request类的具体用法?TypeScript request怎么用?TypeScript request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了request类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: request
static async request (externalId: string, countyCourtJudgment: CountyCourtJudgment, user: User): Promise<Claim> {
return request.post(`${claimStoreApiUrl}/${externalId}/county-court-judgment`, {
body: countyCourtJudgment,
headers: {
Authorization: `Bearer ${user.bearerToken}`
}
})
}
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:8,代码来源:ccjClient.ts
示例2: redetermination
static async redetermination (externalId: string, reDetermination: ReDetermination, user: User, madeBy: MadeBy) {
return request.post(`${claimStoreApiUrl}/${externalId}/re-determination`, {
body: { explanation: reDetermination.text, partyType: madeBy.value },
headers: {
Authorization: `Bearer ${user.bearerToken}`
}
})
}
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:8,代码来源:ccjClient.ts
示例3: calculatePostponedDeadline
static calculatePostponedDeadline (issueDate: Moment): Promise<Moment> {
const url: string = `${claimApiBaseUrl}/deadline`
const from: string = MomentFormatter.formatDate(issueDate)
return request.get(
`${url}/${from}`
).then(response => MomentFactory.parse(response))
}
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:9,代码来源:deadlineCalculatorClient.ts
示例4: calculateInterestRate
static calculateInterestRate (amount: number, rate: number, startDate: Moment, endDate: Moment): Promise<number> {
const url: string = `${claimApiBaseUrl}/interest/calculate`
const from: string = MomentFormatter.formatDate(startDate)
const to: string = MomentFormatter.formatDate(endDate)
return request.get(
`${url}?from_date=${from}&to_date=${to}&amount=${amount}&rate=${rate}`
).then(response => response.amount)
}
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:10,代码来源:interestRateClient.ts
示例5: updateResponseDeadline
static updateResponseDeadline (updateRequest: UpdateResponseDeadlineRequest, user: User) {
if (FeatureToggles.isEnabled('testingSupport')) {
return request.put(
`${testingSupportUrl}/${updateRequest.claimNumber}/response-deadline/${updateRequest.date.asString()}`,
{
headers: {
Authorization: `Bearer ${user.bearerToken}`
}
})
} else {
throw new Error('Testing support is not enabled')
}
}
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:13,代码来源:testingSupportClient.ts
示例6: update
async update (user: User, paymentReference: string, caseReference: string, caseNumber: string): Promise<void> {
checkDefined(user, 'User is required')
checkNotEmpty(paymentReference, 'Payment reference is required')
checkNotEmpty(caseReference, 'Case Reference is required')
checkNotEmpty(caseNumber, 'Case Number is required')
return request.patch({
uri: `${paymentURL}/${paymentReference}`,
body: this.preparePaymentUpdateRequest(caseReference, caseNumber),
headers: {
Authorization: `Bearer ${user.bearerToken}`,
ServiceAuthorization: `Bearer ${this.serviceAuthToken.bearerToken}`
}
}).then(() => Promise.resolve())
.catch(() => Promise.reject())
}
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:15,代码来源:payClient.ts
示例7: context
context('timeouts and retries handling', () => {
const requestDelayInMillis = 500
const retryAttempts = 3
const retryingRequest = request.defaults({
retryDelay: requestDelayInMillis,
maxAttempts: retryAttempts
} as RequestPromiseOptions)
const claimStoreClient: ClaimStoreClient = new ClaimStoreClient(retryingRequest)
describe('saveClaim', () => {
function mockSuccessOnFirstSaveAttempt () {
mock(`${claimStoreApiUrl}`)
.post(`/${claimant.id}`)
.reply(HttpStatus.OK, returnedClaim)
}
it('should retrieve a claim that was successfully saved on first attempt with feature toggles', async () => {
mockSuccessOnFirstSaveAttempt()
const claim: Claim = await claimStoreClient.saveClaim(claimDraft, claimant, 'admissions')
expect(claim.claimData).to.deep.equal(new ClaimData().deserialize(expectedClaimData))
})
it('should retrieve a claim that was successfully saved on first attempt without feature toggles', async () => {
mockSuccessOnFirstSaveAttempt()
const claim: Claim = await claimStoreClient.saveClaim(claimDraft, claimant)
expect(claim.claimData).to.deep.equal(new ClaimData().deserialize(expectedClaimData))
})
function mockTimeoutOnFirstSaveAttemptAndConflictOnSecondOne () {
mock(`${claimStoreApiUrl}`)
.post(`/${claimant.id}`)
.socketDelay(requestDelayInMillis + 10)
mock(`${claimStoreApiUrl}`)
.post(`/${claimant.id}`)
.reply(HttpStatus.CONFLICT, `Duplicate claim for external id ${claimDraftData.externalId}`)
mock(`${claimStoreApiUrl}`)
.get(`/${claimDraftData.externalId}`)
.reply(HttpStatus.OK, returnedClaim)
}
it('should retrieve claim saved on first attempt that timed out and caused a 409 on retry', async () => {
resolveLinkDefendant()
mockTimeoutOnFirstSaveAttemptAndConflictOnSecondOne()
const claim: Claim = await claimStoreClient.saveClaim(claimDraft, claimant, 'admissions')
expect(claim.claimData).to.deep.equal(new ClaimData().deserialize(expectedClaimData))
})
function resolveLinkDefendant () {
mock(`${claimStoreApiUrl}`)
.put('/defendant/link')
.reply(HttpStatus.OK)
}
function mockInternalServerErrorOnAllAttempts () {
mock(`${claimStoreApiUrl}`)
.post(`/${claimant.id}`)
.times(retryAttempts)
.reply(HttpStatus.INTERNAL_SERVER_ERROR, 'An unexpected error occurred')
}
it('should propagate error responses other than 409', async () => {
mockInternalServerErrorOnAllAttempts()
try {
await claimStoreClient.saveClaim(claimDraft, claimant, 'admissions')
} catch (err) {
expect(err.statusCode).to.equal(HttpStatus.INTERNAL_SERVER_ERROR)
expect(err.error).to.equal('An unexpected error occurred')
return
}
expect.fail() // Exception should have been thrown due to 500 response code
})
})
})
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:83,代码来源:claimStoreClient.ts
示例8: createPostcodeToCountryClient
static createPostcodeToCountryClient (): PostcodeToCountryClient {
return new PostcodeToCountryClient(
postcodeLookupApiKey,
request.defaults(requestOptionsOverride)
)
}
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:6,代码来源:clientFactory.ts
示例9: createOSPlacesClient
static createOSPlacesClient (): OSPlacesClient {
return new OSPlacesClient(
postcodeLookupApiKey,
request.defaults(requestOptionsOverride)
)
}
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:6,代码来源:clientFactory.ts
注:本文中的client/request.request类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论