项目作者: LFSousa

项目描述 :
With this module, you can make a request to an endpoint list and map the response to a parameters object
高级语言: JavaScript
项目地址: git://github.com/LFSousa/web-map.git
创建时间: 2019-03-15T17:44:10Z
项目社区:https://github.com/LFSousa/web-map

开源协议:Apache License 2.0

下载


WEB MAP

With this module, you can make a request to an endpoint list and map the response to a parameters object

Installing

  1. npm i web-map

Example

  • Using the initial value: array_index = 2
  1. Make a GET request to http://dummy.restapiexample.com/api/v1/employees
    and map the id of [{{array_index}}] element from the response array into emp_id

  2. Make a GET request to http://dummy.restapiexample.com/api/v1/employee/{{emp_id}}
    where the {{emp_id}} is the value extracted from the previous request
    and map the employee info into new parameters

  3. Map the parameters extracted into a new structure

  1. let {Structure, Endpoints} = require('web-map');
  2. let initialValues = { array_index: 2 };
  3. let endpoints = new Endpoints(
  4. [
  5. {
  6. 'uri': "http://dummy.restapiexample.com/api/v1/employees",
  7. 'method': "get",
  8. 'params': {
  9. "emp_id": "[{{array_index}}][id]"
  10. }
  11. },
  12. {
  13. 'uri': "http://dummy.restapiexample.com/api/v1/employee/{{emp_id}}",
  14. 'method': "get",
  15. 'params': {
  16. "emp_name": "[employee_name]",
  17. "emp_sal": "[employee_salary]",
  18. "emp_age": "[employee_age]"
  19. }
  20. }
  21. ]
  22. )
  23. let struct = new Structure({
  24. employee: "{{emp_name}} ({{emp_age}})",
  25. sal: "${{emp_sal}}"
  26. })
  27. endpoints.extractParams(initialValues).then(params => {
  28. console.log(struct.fill(params).filled);
  29. });