How to in .http file add automatically headers to all requests?
Answered
Hi,
I move my API requests from Postman to Rider and try to use .http files.
I would like to have an option to define default headers for all my API requests,
but I don't see the one in the documentation on page https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html
In general, I would like to include them per request
POST {{base_url}}/my_endpoint
{{ my_headers }}
{
"id": 100
}
or (better) per file/folder/project:
@include_headers {{ my_headers }}
###
GET /request1
###
GET /request2
###
etc.
Best regards,
Dariusz Jankowski
Please sign in to leave a comment.
Does https://www.jetbrains.com/help/idea/exploring-http-syntax.html#using_request_vars help?
No, I know how to define variables. The problem is about headers, how to define them in one place (file, variables, environment, etc.) and use in all (or some) requests.
Probably, the best way would by to add command on the top of a file:
@include_headers(headers.http)
so every request defined in the file will include them also.
Please vote for https://youtrack.jetbrains.com/issue/IDEA-241428/HTTP-Client-Including-API-files.
I see the above linked issue regarding including API files and notices that its already implemented in Rider. However, how does this help me to define default headers for all my request in a certain file?
e.g. I want that all my requests have the header: Accept: application/json
Hi Philipp Reiter, thank you for your clarification.
There is a feature request https://youtrack.jetbrains.com/issue/IJPL-66680 to implement such functionality.
Please vote for this request and add comment with your opinion on how you would like it implemented.