GithubHelp home page GithubHelp logo

pattama / cta-tool-request Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thomsonreuters/cta-tool-request

0.0 1.0 0.0 37 KB

Request wrapper to make http requests for cta projects

License: Other

JavaScript 100.00%

cta-tool-request's Introduction

cta-tool-request

Build Status Coverage Status codecov

Request Modules for Compass Test Automation, One of Libraries in CTA-OSS Framework

General Overview

This modules provides the Request as Tool to make http requests.

If you plan to use it in a Flowcontrol application, try to consider using the brick adapter of this tool cta-brick-request especially if you'd like to expose your http calls contracts in the configuration of your app.

How to use it

Instantiation

const Request = require('cta-tool-request');
const request = new Request();

Supported http methods

All http methods are supported and can be run via the main method "exec".

Example:

request.exec({
  method: 'HEAD',
  url: 'http://api.compass.int.thomsonreuters.com/authorize/v1/userRoles?appId=demo&userId=U1',  
}).then((result) => {
  console.log(result);
}).catch((error) => {
  console.error(error);
})

Although, this module provide shortcuts for the most used methods: GET, POST, PUT, DELETE

Example:

request.get('http://api.compass.int.thomsonreuters.com/authorize/v1/userRoles?appId=demo&userId=U1')
.then((result) => {
  console.log(result);
}).catch((error) => {
  console.error(error);
})

Response

All exported methods are promises that resolve to an object with these fields:

  • status: response status
  • type: response data type (ex. application/json, text/html...)
  • data: response data
  • headers: response headers

More examples

GET via exec method

request.exec({
  method: 'GET',
  url: 'http://domain.com',  
}).then((result) => {
  // ...
})

GET with some headers

request.get('http://domain.com', {'x-from': 'CTA'})
  .then((result) => {
  // ...
  })

Or via exec

request.exec({
  method: 'GET',
  url: 'http://domain.com',
  headers: {'x-from': 'CTA'},
}).then((result) => {
  // ...
})

POST a body

request.post('http://domain.com', {foo: 'bar'})
  .then((result) => {
    // ...
  })  

Or via exec

request.exec({
  method: 'POST',
  url: 'http://domain.com',
  body: {foo: 'bar'},
}).then((result) => {
  // ...
})

POST with body and headers

request.post('http://domain.com', {foo: 'bar'}, {'x-from': 'CTA'})
  .then((result) => {
  // ...
  })

Or via exec

request.exec({
  method: 'POST',
  url: 'http://domain.com',
  body: {foo: 'bar'},
  headers: {'x-from': 'CTA'},
}).then((result) => {
  // ...
})

Other http methods can be used in the same way...

cta-tool-request's People

Contributors

kiettisak-angkanawin avatar panit-tr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.