Code Monkey home page Code Monkey logo

hurl-run's Introduction

hurl-run: A script to run hurl file with extra functionalities

What does this script do

  • Attach extra headers for all requests
  • Interpolate header names and header values using Python functions
  • Define your own Python functions and use them in interpolations
  • Set active environment in a file
  • All unused command arguments in this script are passed to hurl.

How

Set active environment

  1. Create directory envs in the project folder, and put variables in envs/<environment>.env. The format of the file is identical to hurl's --variables-file.
    • Example: local environmental variables should be saved in envs/local.env.
    • Example: dev environmental variables should be saved in envs/dev.dev.
  2. Create file .helper/env, and in the file, indicate the name of the active environment.
    • Example: if .helper/env's content is local, all variables defined in env/local.env will be used in the HTTP request.

Define your own Python functions

  1. Create file .helper/extra-functions.py in the project folder.
  2. Define your Python functions. You are free to import any built-in packages.

Example: Define a function to create a random UUID

import uuid
def random_uuid():
    return str(uuid.uuid4())

Add default headers

  1. Create file .helper/default-headers.json in the project folder.
  2. Define an object in the json file where:
    1. key-value pairs defined in base object are the headers for all environments.
    2. key-value pairs could be defined in a nested object, which means they are for a specific environments.
  3. You can use %%python{<function call>}%% to call the functions defined in .helper/extra-functions.py.

Example: Define default headers

{
  "Header1": "Value1",
  "Header2": "Value2",
  "local": {
    "Header1": "LocalValue1",
    "Header3": "LocalValue3"
  },
  "dev": {
    "Header2": "DevHeader2",
    "UUID": "%%python{random_uuid()}"
  }
}

In this example, if local environment is being used, headers will be sent as:

Header1: LocalValue1
Header2: Value2
Header3: LocalValue3

if dev environment is being used, headers will be sent as:

Header1: Value1
Header2: DevHeader2
UUID: <Result of function call random_uuid()>

For each request, the function is called separately.

hurl-run's People

Contributors

yjlcoder 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.