Search code examples
flutterhttpflutter-webtwitch-api

How to listen and handle POST requests in a Flutter app


I want to use the Twitch API in a web app made in Flutter. When I POST a request, the Twitch server responds by POSTing a request to a callback URL.

I searched the internet, but I couldn't find a way to receive and handle POST request from servers. The Flutter documentation only explains how to do POST requests but not how to receive them.


Solution

  • You can't turn your flutter app into a server which is always online. You can do what you desire by creating an API endpoint, which is always online[server].

    • Create a cloud function. This function is the endpoint where the twitch server will send data.

    • When this cloud function is invoked, use the data that was sent to it from Twitch, to store something in FireStore.

    • In your Flutter app, or any other app, you can listen to changes in this document, using streams. You can also use realtime database from Firebase to achieve this if you don't want firestore.

    Unless you can figure out a way, to keep your app exposed [i.e to have an ip address which is always accessable, from anyone online, which is something I'm sure you don't want.