當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。