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
Settings
service to perform dynamic substitutions:- Create a new
Settings
service (if you don’t have one yet) by going toCREATE NEW > Service > Settings (REST settings)
. - Then, create a new
id
parameter in the newly-createdSettings
and provide a value for it. - Now, go to your REST service, and change the dynamic part of your URL to
{MySettings.id}
whereMySettings
is the settings service name, andid
is 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
id
parameter and provide a value for it. - Change the REST service URL to
http://mywebsite.com/name/{id}/edit
. - Because the value of the
id
parameter 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!