typicode / json-server

Get a full fake REST API with zero coding in less than 30 seconds (seriously)
Other
72.68k stars 7.01k forks source link

Return a blob or pdf from json-server #1269

Open thomashoef opened 3 years ago

thomashoef commented 3 years ago

Hi everyone,

Is there a way to also return a file of type "application/pdf" / Blob type from a path using json-server? We have our mocked data under folder /issues/1.js so that it returns the mock json using URL /issues/1 but we would like to return a PDF from URL /issues/x/doc

Is this possible and how?

Thanks in advance! Thomas

MadhuSaini22 commented 9 months ago

Hi @thomashoef ,

Thanks for raising this issue! I understand your desire to return files like PDFs directly from json-server instead of relying on external solutions. While json-server primarily focuses and is primarily designed to serve JSON data, not raw files.

Alternative Solutions: External File Server: Host PDFs separately on a web server or file server and provide links or URLs to them. Custom Middleware: Extend json-server's functionality with custom middleware to handle file serving. Third-Party Libraries: Consider libraries like serve-static for static file serving.