Home > Enterprise >  Is it possible to get data from the server without passing a tableName parameter? Retrofit
Is it possible to get data from the server without passing a tableName parameter? Retrofit

Time:01-16

@FormUrlEncoded
@POST("Places.php")
Call<List<CountryModel>> getCountries(@Field("tableName") String tableName);

@FormUrlEncoded
@POST("Places.php")
Call<List<CityModel>> getCities(@Field("tableName") String tableName);

@FormUrlEncoded
@POST("Places.php")
Call<List<NeighborhoodModel>> getNeighborhoods(@Field("tableName") String tableName);

I have a PHP file named Places.php and this file provides me the data as a JSON array according to the tableName parameter.

Everything is working well but I want to ask is it possible to get the data from the server according to the method name, Not tableName.

For example, If I called the getCountries method then that means I want to get countries, Is it possible to do that without inserting the table name parameter?

CodePudding user response:

Sure, but this part is to be done from PHP code side first then on Android. Hope this link helps you

https://tutorialsclass.com/php-rest-api-file_get_contents/

CodePudding user response:

Create Restful API in PHP and just call the method. use this exaqmple

Update:

 <? PHP 
   require_once ( "SiteRestHandler.php");
   $ view = "";
   if (isset ($ _GET & # 91; "view" & # 93;))
   $ view = $ _GET & # 91 ; "view" & # 93 ;;
   / *
     * RESTful service controller
     * URL mapping
     * /
   switch ($ view) {

   case "all":
   // Handle REST Url / site / list /
   $ siteRestHandler = new SiteRestHandler ();
   $ siteRestHandler -> getAllSites ();
   break;

  case "single":
  // Handle REST Url / site / show / < id> /
  $ siteRestHandler = new SiteRestHandler ();
  $ siteRestHandler -> getSite ($ _GET [ "id"]);
  break;

  case "":
  // 404 - not found;
  break;
  }
?> 

learn more

  •  Tags:  
  • Related