本文整理汇总了TypeScript中superagent类的典型用法代码示例。如果您正苦于以下问题:TypeScript superagent类的具体用法?TypeScript superagent怎么用?TypeScript superagent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了superagent类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: superagent
export const handler = effects.createEffectHandler(Request, (e, s) => {
const req = superagent(e.data.method, e.data.url);
if(e.data.query)
req.query(e.data.query);
if(e.data.headers)
req.set(e.data.headers);
if(e.data.type)
req.type(e.data.type);
if(e.data.timeout)
req.timeout(e.data.timeout);
if(e.data.body)
req.set(e.data.body);
req.end(function(err, resp) {
if(err)
s(e.data.err(err, resp))
else
s(e.data.ok(resp))
});
});
示例2: request
/** Create a request to Dicoogle.
* @param method - the intended HTTP method ('GET', 'POST', ...)
* @param uri - the URI to the intended service, relative to Dicoogle's base URL
* @returns a superagent object for a new request to this service
*/
public request(method: string, uri: string | string[]): SuperAgentRequest {
const req = superagent(method, [this._url].concat(uri).join('/'))
if (this._token) {
req.set('Authorization', this._token);
}
return req;
}
示例3: buildRequest
private buildRequest(req: Request): request.SuperAgentRequest {
const fullUrl = url.parse(this.conf.launcherBaseUrl)
fullUrl.pathname = req.path
// We might have to encrypt the query values
if (req.query != null) {
if (req.doNotEncrypt) fullUrl.query = req.query
else fullUrl.search = encodeURIComponent(this.encryptAndBase64(querystring.stringify(req.query)))
}
const httpReq = request(req.method, url.format(fullUrl))
if (this.logger != null) this.logger('Calling ' + req.method + ' ' + url.format(fullUrl))
// Set the body
if (req.jsonBody != null) req.rawBody = JSON.stringify(req.jsonBody)
if (req.rawBody != null) {
if (this.logger != null) this.logger('REQ BODY', req.rawBody)
// Encrypt if necessary
if (req.doNotEncrypt) {
httpReq.send(req.rawBody)
if (req.jsonBody != null) httpReq.set('Content-Type', 'application/json')
else httpReq.set('Content-Type', 'text/plain')
} else {
httpReq.set('Content-Type', 'text/plain')
httpReq.send(this.encryptAndBase64(req.rawBody))
}
}
// TODO: stream
httpReq.buffer(true)
// Auth if necessary
if (this.conf.token != null && !req.doNotAuth) httpReq.set('authorization', 'Bearer ' + this.conf.token)
// TODO: Ug - https://github.com/visionmedia/superagent/issues/852
httpReq['then'] = null
return httpReq
}
示例4: makeAPIRequest
export function makeAPIRequest (
{
token,
method,
query,
httpMethod = 'POST'
}: TelegramAPIRequest,
multipart = false
): Observable<TelegramAPIResponseResult | TelegramAPIError> {
let endpoint = `https://api.telegram.org/bot${token}`
let url = `${endpoint}/${method}`
let req = transformReq(request(httpMethod, url).redirects(0), multipart)(query)
return fromSuperagent(req)
.catch(e => $.throw(e instanceof Error ? e : new Error(e)))
.map<TelegramAPIResponse>(res => res.body)
.map(body => body.ok
? $.just(body.result)
: $.throw(body))
.switch()
}
示例5:
request
.get('/some-url')
.use(prefix) // Prefixes *only* this request
.use(nocache) // Prevents caching of *only* this request
.end(function(err, res){
// Do something
});
var callback = (err: any, res: request.Response) => {};
// Request basics
request
.get('/search')
.end(callback);
request('GET', '/search')
.end(callback);
request
.get('http://example.com/search')
.end(callback);
request
.head('/favicon.ico')
.end(callback);
request
.del('/user/1')
.end(callback);
request