How to use the k6/http.post function in k6

To help you get started, we’ve selected a few k6 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github grafana / grafana / devenv / docker / loadtest / modules / client.js View on Github external
formPost(url, body, params) {
    params = params || {};
    this.beforeRequest(params);
    this.onBeforeRequest(params);
    return http.post(this.url + url, body, params);
  }
github poetapp / frost-api / tests / stress / createToken.js View on Github external
export default (token) => {
  const url = `${FROST_HOST}/tokens`
  const params =  { headers: { 'Content-Type': 'application/json', token } }
  const res = http.post(url, {}, params)

  check(res, {
    'status 200': (r) => r.status === 200
  })

  sleep(1)
}
github poetapp / frost-api / tests / stress / createWork.js View on Github external
export default ({ token, work }) => {
  const url = `${FROST_HOST}/works`
  const params =  { headers: { 'Content-Type': 'application/json', token } }
  const res = http.post(url, work, params)

  check(res, {
    'status 200': (r) => r.status === 200
  })

  sleep(1)
}
github vendure-ecommerce / vendure / packages / dev-server / load-testing / utils / api-request.js View on Github external
post(variables = {}) {
        const res = http.post('http://localhost:3000/shop-api/', {
            query: this.document,
            variables: JSON.stringify(variables),
        }, {
            timeout: 120 * 1000,
        });
        check(res, {
            'Did not error': r => r.json().errors == null && r.status === 200,
        });
        const result = res.json();
        if (result.errors) {
            fail('Errored: ' + result.errors[0].message);
        }
        return res.json();
    }
}
github poetapp / frost-api / tests / stress / createAccount.js View on Github external
export default () => {
  const email = `user${Date.now()}+${__VU}@po.et`;
  const payload = JSON.stringify({ email, password: 'aB%12345678910' })

  const url = `${FROST_HOST}/accounts`
  const params =  { headers: { 'Content-Type': 'application/json' } }
  const res = http.post(url, payload, params)

  check(res, {
    'status 200': (r) => r.status === 200
  })

  sleep(1)
}
github kyma-project / kyma / tests / perf / components / application-gateway / application_gateway.js View on Github external
export default function () {
    let res = http.post(configuration.url, configuration.payload, configuration.params);

    check(res, {
        "status was 200": (r) => r.status == 200,
        "transaction time OK": (r) => r.timings.duration < 200
    });
    sleep(1);
};
github jembi / hearth / performance / patient-encounter-observation-create.js View on Github external
const createEncounter = (patientId) => {
  encounterResource.patient.reference = `Patient/${patientId}`

  const response = http.post(
    `${BASE_URL}/fhir/Encounter`,
    JSON.stringify(encounterResource),
    {
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json+fhir'
      },
      tags: {
        name: 'Create Encounter Resource'
      }
    }
  )
  check(response, {
    'status code for encounter create is 201': r => r.status === 201
  })
github jembi / openhim-core-js / performance / load.js View on Github external
function makePostRequest() {
  const response = http.post(
    `${BASE_URL}/mediator`,
    '{"hello": "world"}',
    {
      headers: {
        Accept: 'application/json',
        Authorization: 'Basic cGVyZm9ybWFuY2U6cGVyZm9ybWFuY2U=',
        'Content-Type': 'application/json'
      },
      tags: {
        name: 'Post request'
      }
    }
  )
  check(response, {
    'status code is 200': r => r.status === 200
  })
github jembi / hearth / performance / patient-encounter-observation-create.js View on Github external
const createObservation = (observation, patientId, encounterId) => {
  observation.context.reference = `Encounter/${encounterId}`
  observation.subject.reference = `Patient/${patientId}`

  const response = http.post(
    `${BASE_URL}/fhir/Observation`,
    JSON.stringify(observation),
    {
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json+fhir'
      },
      tags: {
        name: `Create Observation Resource`
      }
    }
  )
  check(response, {
    'status code for observation create is 201': r => r.status === 201
  })
github Squidex / squidex / backend / tools / k6 / shared.js View on Github external
function getToken(clientId, clientSecret) {
    const tokenUrl = `${variables.serverUrl}/identity-server/connect/token`;

    const tokenResponse = http.post(tokenUrl, {
        grant_type: 'client_credentials',
        client_id: clientId,
        client_secret: clientSecret,
        scope: 'squidex-api'
    }, {
        responseType: 'text'
    });

    if (tokenResponse.status !== 200) {
        throw new Error('Invalid response.');
    }

    const tokenJson = JSON.parse(tokenResponse.body);

    return tokenJson.access_token;
}