Mobile Tip: Dynamic REST API URLs in AngularJS Apps
Dynamic URLs are very common in any mobile app. When building AngularJS apps with Appery.io there are few ways to make parts of the URL (or even the entire URL) dynamic. We’ll use this URL for our example: http://mywebsite.com/name/{id}/edit , where the {id} part should be dynamic.
- First of all, you can use the
Settingsservice to perform dynamic substitutions:- Create a new
Settingsservice (if you don’t have one yet) by going toCREATE NEW > Service > Settings (REST settings). - Then, create a new
idparameter in the newly-createdSettingsand provide a value for it. - Now, go to your REST service, and change the dynamic part of your URL to
{MySettings.id}whereMySettingsis the settings service name, andidis the name of the parameter. Your URL should look like:http://mywebsite.com/name/{MySettings.id}/edit
- Create a new
- Alternatively, you can create request parameters directly in the REST service. They will be automatically substituted if names coincide. You can use this approach if you need visual Mapping for dynamic parameters:
- Go to your REST service
Request > Query String. - Create the new
idparameter and provide a value for it. - Change the REST service URL to
http://mywebsite.com/name/{id}/edit. - Because the value of the
idparameter will be automatically inserted to the{id}placeholder, it won’t be added to the end of the URL as a query string.
- Go to your REST service
Read more about the REST and Settings services in AngularJS.
Make sure to check out all of our mobile development tips.
Do you want to build apps fast? Start developing with our trial plan!
