Add JSON for /tags

AI-generated summary

The discussion revolves around adding a JSON representation for the /tags endpoint. johnmuhl initially requested the feature, and DeanMarkTaylor discovered that sending the X-Requested-With: XMLHttpRequest HTTP header returns JSON. However, eviltrout explained that supporting the “.json” extension is not feasible due to tags being able to contain periods.

Instead, eviltrout recommended using the Accept header with application/json to request JSON, as seen in this example:

curl "https://meta.discourse.org/tags" -H "Accept: application/json"

This approach is preferred as it explicitly requests JSON and is more suitable for API consumption.

Could a JSON representation be added for /tags?

Requesting with the following HTTP header returns JSON:
X-Requested-With: XMLHttpRequest

You can try it for yourself with CURL:

curl "https://meta.discourse.org/tags"  -H "X-Requested-With: XMLHttpRequest"

Although supporting the “.json” extension would make it the same as many other endpoints.

4 лайка

Tags can now have periods in them so that’s unfortunately not going to happen.

We lose a little discoverability but on the other hand only developers really want the JSON feeds and they can figure it out easily!

2 лайка

Ahh, got ya - that does make it awkward.

Thanks for clarifying the reasoning.

Could you confirm that adding the “X-Requested-With: XMLHttpRequest” header is the correct (best) way to force JSON request?

It doesn’t seem quite specific enough - it feels like we should be requesting JSON rather than making adding the fake X-Requested-With header.

Actually we support the Accept header, so this approach is preferred as our API needn’t be consumed by XHR:

curl "https://meta.discourse.org/tags" -H "Accept: application/json"
3 лайка