Skip to content
Advertisement

How to create a json php api that only connects given with the expo react native app?

I have the following PHP code where I intend to convert it into an API to show my sports news that is hosted in a PHP application and the data stored in MYSQL, so I want to show those records of my news in an application developed in Expo React Native.

JavaScript

The code already generates a JSON structure for me, printing the data in JSON in such a way:

JavaScript

But I this route example.com/api/json.php I have to create a code, a key that allows only the connection with the application only the app that has the access key with the application will show the data, this key in some Examples that I have seen, I realize that some parameters pass through the url.

So my question is, how to print the data in expo react native but that the data call is linked with a key between the app and the api json php

Advertisement

Answer

First , in your app , you have a secret key (e.g. Stackoverflow1234#@$%x) which nobody knows.

and in your php, you can use this

JavaScript

and in your react-native app, you can use https://www.yourdomain.com/xxx.php?key=Stackoverflow1234#@$%x to get the data, such as:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement