apollo-server icon indicating copy to clipboard operation
apollo-server copied to clipboard

add HEAD requests in RESTDataSource Class

Open devdudeio opened this issue 4 years ago • 8 comments

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)
        ...
    }
}

devdudeio avatar Aug 07 '19 10:08 devdudeio

Is there any progress on this topic? I would love to use this enhancement :)

meverlee avatar Oct 13 '19 17:10 meverlee

Is there any update on this? I also need to make HEAD method request using RESTDataSource but there is no support for that.

shipraguptaa avatar Nov 14 '19 09:11 shipraguptaa

@abernix Any update?

shipraguptaa avatar Dec 10 '19 11:12 shipraguptaa

it’s not the best solution but if you need a fast solution just use fetch and do a HEAD request

devdudeio avatar Dec 23 '19 21:12 devdudeio

@abernix Any update on this? We recently ran into this issue.

Phoenix1405 avatar Nov 16 '20 19:11 Phoenix1405

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.

abernix avatar Nov 17 '20 10:11 abernix

I just passed the header into my returned data as a symbol

devdudeio avatar Nov 23 '20 13:11 devdudeio

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.

kettanaito avatar Jun 07 '22 14:06 kettanaito