当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript superagent类代码示例

本文整理汇总了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))
    });
});
开发者ID:meknhq,项目名称:relm,代码行数:25,代码来源:request.ts

示例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;
 }
开发者ID:bioinformatics-ua,项目名称:dicoogle-client-js,代码行数:12,代码来源:socket.ts

示例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
 }
开发者ID:Artogn,项目名称:safeclient.js,代码行数:38,代码来源:client.ts

示例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()
}
开发者ID:goodmind,项目名称:cycle-telegram,代码行数:21,代码来源:api-request.ts

示例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
开发者ID:AlBlanc,项目名称:DefinitelyTyped,代码行数:31,代码来源:superagent-tests.ts


注:本文中的superagent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。