0.3.0 • Published 2 years ago

@ndrsg/nx-http v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

GitHub Workflow Status codecov npm npm

@ndrsg/nx-http

A @nrwl/nx plugin for executing http-requests e.g. for webhooks or API calls, file upload and file download

Installation

npm install --save-dev @ndrsg/nx-http

Usage

You can use system environment variables in all option values, e.g. for setting up an 'Authorization' header.\ But options.env is only used for request-data!

Webhooks

nx run project-name:hook
{
  "sourceRoot": "...",
  "projectType": "...",
  "targets": {
    "hook": {
      "executor": "@ndrsg/nx-http:request",
      "options": {
        "url": "https://webhook.site/5c0e348f-d188-4e54-8f6f-79efc75a87fe",
        "method": "POST",
        "data": {
          "custom": "data"
        },
        "headers": {
          "Content-Type": "application/json"
        },
        "query": {
          "queryparam1": "1",
          "queryparam2": "2"
        },
        "responseFilePath": "./fileoutput/test-hook.json"
      }
    },
    "create-page": {
      "executor": "@ndrsg/nx-http:request",
      "options": {
        "baseUrl": "https://my-wiki",
        "url": "/home",
        "method": "POST",
        "fromFile": "./testfiles/template.html",
        "headers": {
          "Authorization": "Bearer $CI_AUTHORIZATION_TOKEN"
        },
        "systemEnv": true,
        "env": {
          "CONTENT": "<p>Released nx-http</p>"
        }
      },
      "configurations": {
        "dev": {
          "url": "/dev",
          "env": {
            "CONTENT": "<p>Realeased nx-http DEV</p>"
          }
        }
      }
    }
  }
}

template.html for nx run my-project:create-page

<html>
  <body>
    <div>
      $CONTENT
    </div>
    <div>
      $CI_BRANCH_NAME
    </div>
  </body>
</html>

File Upload

nx run project-name:upload
{
  "sourceRoot": "...",
  "projectType": "...",
  "targets": {
    "upload": {
      "executor": "@ndrsg/nx-http:upload",
      "options": {
        "url": "https://webhook.site/5c0e348f-d188-4e54-8f6f-79efc75a87fe/07cbd7de-0b89-412a-b29f-66ec78f1693b",
        "sourcePath": "./packages/nx-http/README.md",
        "headers": {}
      }
    },
  }
}

File Download

nx run project-name:download
{
  "sourceRoot": "...",
  "projectType": "...",
  "targets": {
    "download": {
      "executor": "@ndrsg/nx-http:download",
      "options": {
        "url": "https://webhook.site/token/5c0e348f-d188-4e54-8f6f-79efc75a87fe/request/0138ee58-d9a2-408e-b303-07557c759bfb/download/32702fb1-135f-4fd1-bcb0-a3fecda98a26",
        "targetPath": "./fileoutput/download.md"
      }
    },
  }
}
0.3.0

2 years ago

0.2.0

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago