I need Locust to group calls to the same endpoint with different inline parameters together in html reports [duplicate] - locust

I have a task that has two posts requests. The first post request creates the parent and the second uses the key from the parent to create a child of that parent. However in the output, while all the parent post endpoints are rolled up, the child ones are not because they include the parent ID in the endpoint URL.
How can I have the output roll up by endpoint where it uses a placeholder for the id.
Parent Endpoint
/v1/foo/bar
Child Endpoint
/v1/foo/bar/{id}/upload
Actual
With the above examples, I get one line in the output for the parent and it shows the number of requests, failures, etc., and I get one line for each child request. So if the parent has 50 requests on it I will have 50 separate lines one for each child request. Something like this is what currently is in the output.
Type
Name
# Requests
# Fails
...
POST
/v1/foo/bar
3
0
POST
/v1/foo/bar/1/upload
1
0
POST
/v1/foo/bar/2/upload
1
0
POST
/v1/foo/bar/3/upload
1
0
Would Like
I don't want the web or CLI output to show for each unique ID, just to be rolled up under one like shown with a placeholder. Something similar to this, but anything that shows the two lines with the counts matching is fine.
Type
Name
# Requests
# Fails
...
POST
/v1/foo/bar
3
0
POST
/v1/foo/bar/{id}/upload
3
0

When you make the request, you can pass in name='/v1/foo/bar/{id}/upload' and that's what Locust will report it as. From the docs:
Each of the methods for making requests also takes two additional optional arguments which are Locust specific and doesn’t exist in python-requests. These are:
Parameters:
name – (optional) An argument that can be specified to use as label in Locust’s statistics instead of the URL path. This can be used to group different URL’s that are requested into a single entry in Locust’s statistics.

Related

Determine the proper REST API method

I have the following functionalities in my API:
Getting a user by their name
Getting a user by their ID
Getting a user, or if it doesn't exist create one
Getting multiple users by their ID
Currently I'm handling the two first functionalities with a GET request, and the third with a POST request. I could use a GET request for getting multiple users, but sending potentially hundreds of IDs through a query parameter seems like the wrong approach, as I would get a very long URL. I could also use a POST request to send the long list of IDs through its body, but I doubt a POST request is meant for this purpose.
What method would be appropriate to use for the last one?
I see 2 possible ways here:
Get all users and do your filtering post response.
Get a range of IDs, which resumes to only 2 parameters, the lower and the upper limits of the interval. (If this satisfy your needs)
Behaving the way you described and avoiding long URLs in the same time will not work together.

Is it considered RESTful if single POST requests create multiple resources?

We have customers API that takes {customer-name, customer-mobile, customer-email} and creates customer in the database.
We also have order API that takes {productId, customer-name, customer-mobile, customer-email}.
The code for order API:
First creates customer based on {name,mobile,email} passed in the order API and return back customerId.
The {productId, customerId} further gets saved in the database in the order table.
Is this restful practice that one API is internally first creating some other resource?
Please note that its an over simplified example where API expects only one type of product in the order API.
It's fine for a single POST call to result in multiple resources being created. It's not generally the best idea but there are use cases where it makes sense - example cases might include (usual legal disclaimer... not limited to...)
the POST method is to the parent resource of all the created resources. So, a POST /accounts call might result in an /accounts/<accountId> resource being created but also an /accounts/<accountId>/tweets resource. In this instance, the /accounts/<accountId> parent is the 'actual' resource being created.
the POST method might create multiple resources representing multiple ways in which the resource may interact with other parts of the system. So, a POST /accounts response might create resources under /accounts/<accountId> and /users/<accountId> (because an account is-a user and user id are a super set of account ids, for arguments sake). However, the client really only gets told about the one under the '/accounts' path (via the Location header). The other created resource is basically a side-effect.
The key point, really, is that the POST method returns a single Location header - representing the 'primary' resource created - and that subsequent 'GET's on that URI are capable of locating any the other resources via links.
If you find yourself in a situation where creating multiple resources via a single POST request results in you having to return different values for the Location header, then something's wrong with your resource breakdown. It should be clear that a 'POST' will always create one particular type of resource, a URI to being returned in the header. Other resources might be created as side-effects.

cq5 not returning child pages json data on '...infinity.json' request

Even though following path http://localhost:4502/content/geometrixx/en/products.infinity.json returning folllowing json.
But same page request in my upper environments (DEV, Stage, QA boxes) returning following json
Can anyone shed some light on this ? I am trying to read child pages data for one of the component and it is working great in local but not in upper environment boxes.
Thank you!
Given that these are stage / production instances, it's possible that additional security measures were taken. If you look at the security checklist, you will see it recommends limiting number of nodes exposed by the Sling Get Servlet [0]:
https://docs.adobe.com/docs/en/aem/6-1/administer/security/security-checklist.html
So if the json.maximumresults property of the Apache Sling Get Servlet was set to 5, the page.infinity.json request won't return all the nodes in the tree.
If you have access to the instance's configuration manager (/system/console/configMgr), you can check the value of the json.maximumresults property for this servlet.
[0] https://github.com/apache/sling-org-apache-sling-servlets-get/blob/dd8af0d1d4c9666ffb16d5324a47e41ba413d973/src/main/java/org/apache/sling/servlets/get/impl/DefaultGetServlet.java#L126
The second response looks like you are hitting the jcr:content sub node directly
/content/geometrixx/en/products/jcr:content.infinity.json
The reason I say this, is that the response in your second request is the same as the graph beneath your jcr:content node in the first response.
If the request is the same, you might want to look at your resource mappings to see if something is modifying your request.

REST collections: pagination enabled by default?

I am trying to figure out what is the common way to respond on GET operation to retrieve multiple resources. For example, if user calls: /books or /books?name=*foo* etc what should good REST api return?
[A] list of all resources in collection. Only if user specifies a range (using start and limit or in any other way), then only a page of results is returned.
[B] always return a first page of resources, even when nothing is specified. Then user may continue with pagination, using the parameters (or any other way).
[C] a document indicating that paging is be involved, with total number of resources in the collection, but without any returned resource; with appropriate status code set (like 300 if I remember correctly at this moment). This response indicates to the user that he can start fetching its data using pagination parameters.
I like C approach, but could not find APIs that are having this.
This depends on either the pagination parameters are mandatory or not. For most APIs it's mandatory simply because /books could return millions of entries.
How about [D]: a redirect.
If the client accesses /books or /books?name=foobar redirect it to /books?page=1&size=15 or /books?name=foobar&page=1&size=15 and return results according to those default parameters.
You could also include pagination links into your response (as per HATEOAS) with a rel attribute that specifies that a link is for the next page, previous, first or last page, so the client can also navigate back and forth between the result pages.

Good Restful design: different payload for different accounts for same url

Is it considered bad design if one url accepted different payloads depending on the basic authentication used? for instance:
http://localhost/userA PUT by userA is allowed up pass XML_A but
http://localhost/userA PUT by adminA is allowed up pass XML_B which is XML_A plus more.
in otherwords it is the same resource but what can be updated is determined based off of the credentials supplied.
I have seen conversations about return data but not too many about request payloads. (not sure if it would be considered different) thanks
UPDATE
Based off of Darrel Miller information, would the following be a better design?
GET /{Username} readonly resource returns different payload based off of rights
GET /{Username}/UpdInfo returns only updatable info (subset of GET /{Username})
PUT /{Username}/UpdInfo updates info 1 to 1 from the GET /{Username}/Info
GET /admin/{Username}/UpdInfo returns updatable info (larger subset of GET /{Username})
PUT /admin/{Username}/UpdInfo updates info 1 to 1 from the GET /admin/{Username}/Info
The problem I see is that PUT method replaces the entire contents of the resource that is targeted. e.g if the following sequence occured,
PUT /UserA with XML_B
PUT /UserA with XML_A
GET /UserA returns XML_A
UserA no longer contains the extra information contained in XML_B.
It think you would be better to just represent the two different sets of information as different resources:
GET /admin/UserA
PUT /admin/UserA with XML_B
GET /UserA
PUT /UserA with XML_A