- Home /
Making a RESTful application with Unity and Azure
I have a fairly complicated question and I have spent the last week researching to find an answer. I will do my best to break my question down into sections, please feel free to answer pieces if you don't know the whole solution!
[OVERVIEW]
I am trying to make an app for education with unity but I need to setup a database in order to handle things like login and student scores. The app will be a WebGL build hosted either on Azure or Itch.io. Ideally I will have the client call a function on the server and ask it for information, then have the information returned. I would also need to be able to send parameters for the server to make the queries against the database. For example, a user attempts to login by putting their username and password into the client. The client sends those two pieces of information to the server for validation. The server checks if the two pieces match and sends the result back to the client. Unfortunately it isn't exactly clear how I should do this in the most effective way. In the next section I will break down the problems.
[PROBLEMS]
Sending information from Unity. Unity has a built in class called UnityWebRequest which is supported in the WebGL build. With this class I should be able to send a request to my server and get a response back. The problem is I am not quite sure how to structure the data so I can read it on the server. I think that it should be sent as JSON data because that is one of the ways to communicate with HTTP. It is also a little unclear exactly what the http address for my functions will be when I call them on the server, but I will get more into that in the next section. In summary The question is how do I structure the data to be sent so I can parse in on the server.
Building functions in the cloud. Using Azure I think there are a few ways I could handle this, but I am not sure which would be most appropriate. I could use Easy APIs, which are associated with a mobile app and linked to my database. I could also use the Function App and just write different functions to handle the queries. Or I could build a .net application in Visual Studio and publish it to Azure. This part is more of a please advise section, as I believe I can do what I need to do with any of those options. I am also confused on exactly what the url for the function being called would be.
Receiving the data from the HTTPRequest. This seems pretty tricky to me. I have seen examples in both node.js and asp.net that take in information and query a database, but it still seems complicated to me. If someone could maybe just mock up an example for my main problem I think it would be very helpful, IE. passing a username and password and pulling those pieces of information out of the request.
Sending the information back to the client. It seems like the best way to handle this is just to format the data as JSON and pass it back through res.Send() or something equivalent in c#. Again I think an example will be the most appropriate here.
I had no experience in this prior to last week and apologize if any of my assumptions are really bad. Ultimately any advice or examples would be most helpful.
Thanks!