single-request.js
1import http from 'k6/http';2import { sleep, check } from 'k6';3import { Counter } from 'k6/metrics';4
5// A simple counter for http requests6
7export const requests = new Counter('http_reqs');8
9// you can specify stages of your test (ramp up/down patterns) through the options object10// target is the number of VUs you are aiming for11
12export const options = {13 stages: [14 { target: 20, duration: '1m' },15 { target: 15, duration: '1m' },16 { target: 0, duration: '1m' },17 ],18 thresholds: {19 http_reqs: ['count < 100'],20 },21};22
23export default function () {24 // our HTTP request, note that we are saving the response to res, which can be accessed later25
26 const res = http.get('http://test.k6.io');27
28 sleep(1);29
30 const checkRes = check(res, {31 'status is 200': (r) => r.status === 200,32 'response body': (r) => r.body.indexOf('Feel free to browse') !== -1,33 });34}