Hi everyone.
I've been wondering if it would be a good idea to use HTTP requests to call backend functions. Let me explain. When you call a backend function (after importing it), Wix actually just sends a request to the server telling it to call the specified function from the backend. This is great and all, expect when you want a little more control. Say you want to change the headers of the request, the content-type (which is JSON by default) or the method from POST to GET. You could even get the request IP and set/get cookies. Well... Wix does have a way of receiving requests - with the http-functions.js file. However, I think this feature is only intended to be used to create a public API for your site. Here's what the doc reference says:
HTTP functions allow you to expose the functionality of your site as a service. That means other people can write code to consume the functionality you expose by calling the functions of the API that you define.
IMPORTANT: This API is only intended for use in server-to-server communications. If you use this API to set a cookie on a site visitor's browser you may no longer be in compliance with applicable data privacy regulations.
But, I don't see why it isn't a good idea to you use this feature for internal use (calling backend functions, e.g. add a like to a post). You just send a request with the fetch function. It's essentially the same thing that Wix does when you call a backend function from frontend - it just sends a request. The difference, as mentioned before, is that with the http-functions feature you can "customize" the request (headers, method) and get the IP. I know this feature is intended for use in server-to-server, but that's only true if you want it to be a public API, not if you want this to be an "internal" API.
I hope I made myself clear. Now I want to hear from you guys. What do you think? Am I wrong? If so, how and why? I'm not a professional in this kind of stuff, I just know some things.
Seems like "http-functions.js" is the only way to set Cookies no?
I have a custom sign in method, and I want to setup a session. Store stuff in a Database collection. The final step is to set a cookie with the "session id"