Implementing HTTP Content Negotiation in Node.js + Express.js

How I Made One API Endpoint Return Both JSON and XML 🚀 A client once came to me with a simple request… “Can your API return both JSON and XML, depending on what we need?” “Wait, from the same endpoint?” was my initial thought. 🤔 But then I realized: that’s exactly what HTTP Content Negotiation is for. Here’s how I implemented it in Node.js + Express.js 👇 // Code ⬇️ How it works: Client sends Accept: application/json → gets JSON Client sends Accept: application/xml → gets XML Same endpoint, two formats, no duplication, just smart logic 💡 This approach made the integration seamless for multiple systems (old + new), and the client loved the flexibility. It’s a small detail that can make your APIs look a lot more professional and scalable. #NodeJS #ExpressJS #BackendDevelopment #API #WebDevelopment #JavaScript #RESTAPI #Developers

  • text

To view or add a comment, sign in

Explore content categories