New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] Sending requests with dynamic body #330
Comments
There sure is. Use JSON target format which allows you to set the request body of each target. Paired with the jq tool, it should be fairly easy to do what you need. |
Here's a specific incantation for you: jq -ncM 'while(true; .+1) | {method: "POST", url: "http://localhost:6060", body: {entityName: "burger", entityId: .} | @base64}' | \
vegeta attack -lazy --format=json -duration=30s | tee results.bin | vegeta report |
Thanks @tsenart |
Yes. A tr := func(id uint64) vegeta.Targeter {
type entity struct {
Name string `json:"entityName"`
ID uint64 `json:"entityId"`
}
return func(t *Target) (err error) {
t.Method = "POST"
t.URL = "http://localhost:6060"
t.Body, err = json.Marshal(&entity{
Name: "burger",
ID: atomic.AddUint64(&id, 1),
})
return err
}
}(0) |
Great. Thanks, that works for me! |
I have a big json and hence I cannot add the post request and body and header here. |
@akashdas2019: Better write a script or little program that does that. |
How about doing with 2 requests ? |
Question
Hi @tsenart
I have a question about request body.
Lets say I have API to create an entity in db and the request body looks like
Now I want to test that API and send 100 requests. The problem is that field
entityId
has to be unique.So, my question is - is there any way to generate unique value for field before sending request to API endpoint?
The text was updated successfully, but these errors were encountered: