'How to determine API url from code in API Gateway Deployments

Our application is deployed behind nginx and Kong API Gateway. The backend is behind the firewall. Only nginx and kong are exposed to the outside world. Please refer to the attached screenshot.

Our code needs to call a third party async api that accepts a callback-url. How do we generate the callback-url such that the third party service calls back our service via kong?

Without the firewall, nginx and kong setup we had the following code that was working so far but this doesn't work now. It generates the url as below http://kong-server-name:8000/my-spring-app/api/v1/callback which is incorrect. The server-name and port number are referring to kong but rest of the path is the context path of my-spring-app.

String baseUrl = ServletUriComponentsBuilder.fromRequestUri(request)
                    .replacePath(null)
                    .build()
                    .toUriString();
                    
callbackUrl = baseUrl + this.contextPath + EndPointReferer.CALLBACK;

Thanks.

enter image description here



Solution 1:[1]

You can use shared preferences to save and retrieve simple data

save data

val sharedPref = activity?.getPreferences(Context.MODE_PRIVATE) ?: return
with (sharedPref.edit()) {
    putInt("MY_COINS", coins)
    apply()
}

Read data

val sharedPref = activity?.getPreferences(Context.MODE_PRIVATE) ?: return
val coins = sharedPref.getInt("MY_COINS"), defaultValue)

Solution 2:[2]

You can use Shared Preferences for state management or save data in key-value pair.

lateinit var shared : SharedPreferences

 override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_spactivity)

        shared = getSharedPreferences("CoinsDB" , Context.MODE_PRIVATE)
        var coins = 0

For Save

 val edit = shared.edit()
 edit.putInt("coins" , coins )
 edit.apply()

For retrieve or read

val coinsValue = shared.getInt("coins")

Solution 3:[3]

I recommend using storage in files if that isn't a problem for you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mr.Droid
Solution 2 Nisha Jain
Solution 3 Nyck