apollo-server
apollo-server copied to clipboard
add HEAD requests in RESTDataSource Class
Some endpoints of my REST API can be requested via a HEAD request but head is not implemented yet.
export class MyFancyAPI extends RESTDataSource {
async countFancyDataset() {
const response = await this.head(`countFancyDataset`); // myFancyDataset: 413212 (in Response Header and body will be empty)
...
}
}
Is there any progress on this topic? I would love to use this enhancement :)
Is there any update on this? I also need to make HEAD method request using RESTDataSource but there is no support for that.
@abernix Any update?
it’s not the best solution but if you need a fast solution just use fetch and do a HEAD request
@abernix Any update on this? We recently ran into this issue.
I don't have the precise answer as to the exact "why", but I could certainly believe that the omission of HEAD
from the original implementation was because it wasn't fully realized that there was much in the way of data to be retrieved from such an endpoint (that doesn't return a body).
That said, data obviously comes in various forms and it's entirely possible to return certain valuable data as header values, so I think the need resonates with me too.
Thanks for opening the pull request, @Phoenix1405.
I just passed the header into my returned data as a symbol
I believe HEAD
requests can also compute data, just not return a body. That can be cached with RESTDataSource
, so the addition of the HEAD
method is quite practical.