Sunday 29 March 2020

Use node application to send JSON and html content

I can't find any good information about how to do following:I have an API, programmed in node, that sends JSON, for example to GET /users.Now, I want to send HTML if a user tries to open the GET /users via a browser. How am I supposed to do that?I thought about doing a subdomain for the API (api.domain.com/users) and a main domain for web requests. Do I have to write a complete separate back-end for both?Or can I send in one application different results? Like res.json({information}) for requests that aren't web based and res.render(some ejs file) for web content? What is the recommended way of doing something like this?(My goal would be to just run one heroku server, to minimize cost)

Submitted March 29, 2020 at 11:51AM by hertelukas

No comments:

Post a Comment