Dynamic endpoint
droidizer opened this issue · comments
Hello,
Is there a way I could dynamically set the endpoint instead of hard coded base url?
Like @url annotation? I see setEndpoint is not optional.
Greeting @droidizer
I really like WASP, so I try to help each time I can, please excuse me if Im not getting this, but, maybe you are looking for:
- Creating an interceptor https://github.com/orhanobut/wasp/wiki/Request-interceptor
- Or perhaps, fi you have multiple endpoints, something like this https://github.com/orhanobut/wasp/wiki/Multiple-end-points
Hope to help
I have just one endpoint but imagine I need to ask the user to enter the
url.
In that case I do not have a base url. I want to pass the user entered url
to the api call.
Kind Regards,
Sowmya.
On Wed, May 4, 2016 at 5:54 PM, Erick Navarro notifications@github.com
wrote:
Greeting @droidizer https://github.com/droidizer
I really like WASP, so I try to help each time I can, please excuse me if
Im not getting this, but, maybe you are looking for:
- Creating an interceptor
https://github.com/orhanobut/wasp/wiki/Request-interceptor- Or perhaps, fi you have multiple endpoints, something like this
https://github.com/orhanobut/wasp/wiki/Multiple-end-pointsHope to help
—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#141 (comment)
That doesnt seem hard:
- In whatever activity you are gonna ask the user to set the endpoint, create a simple EditText and a Button as a trigger, in the layout.
2.- Then in the .java file the behaviour you have to code is; when the user press the button you get the EditText view, get the text (yes, toString) and then save that string in a SharedPrefference (documentation for that http://www.sgoliver.net/blog/preferencias-en-android-i-shared-preferences/). You want to use SharedPreference to store the URL user input, otherwise you will have to ask it each time.
3.- Dont forget to validate correct format and not empty url, etc.
4.- Create an interceptor which will get the endpoint from the Shared preference memory.
5.- Invoke the interceptor wherever you need it.
If for any reason the user is not gonna do this once, but several times during the use of the app (the user will have to type several urls as in a web explorer), then the most usable approach is to create a storable model. Store every model in the app database and use an autocomplete edit text for inputing the urls suggesting the matches from previous url to the user.
Hope to help, any other question I could help I will be glad :)
Oh ok. So, it overrides the base url. Missed that. Thanks for the detailed explanation. Tbh I like wasp too. :)