Using PUT method instead of GET

603 views
Skip to first unread message

har...@gmail.com

unread,
Aug 7, 2015, 6:39:17 AM8/7/15
to Glide
In my app I have a use case where I can get the current image for specific URL with a GET request. But if I add some additional parameters to the URL and do a PUT request then I would get a different image per the values in the URL.
I haven't been able to figure out how i can override the request method Glide uses. Can someone point me to the correct direction?


All the best:
Harri

Róbert Papp

unread,
Aug 7, 2015, 6:48:04 AM8/7/15
to har...@gmail.com, Glide

That's interesting design. For me PUT means you put something on the webserver, and don't expect to get anything.

However you can write a ModelLoader for a spefic model class (see the custom sizes wiki on GitHub) that results in a DataFetcher which makes the PUT request. Look at how HttpUrlFetcher and integration libraries are written.

It may be easier to change the URL API and change that PUT to GET if you have access.

+Robi

--
You received this message because you are subscribed to the Google Groups "Glide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glidelibrary...@googlegroups.com.
To post to this group, send email to glidel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glidelibrary/bb75bdb4-ebb8-45e0-9f91-2c5ccb689533%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

har...@gmail.com

unread,
Aug 7, 2015, 6:56:22 AM8/7/15
to Glide, har...@gmail.com
Hei!


> For me PUT means you put something on the webserver, and don't expect to get anything.
Well, you do. The GET request returns current state, the PUT request changes the user selection. And then returns the new image as the result. Keeping the PUT data in URL is not REST like, yes. But I guess they first made separate requests for these two things and then stated to optimize:)


> However you can write a ModelLoader for a spefic model class (see the custom sizes wiki on GitHub) that results in a DataFetcher which makes the PUT request. Look at how HttpUrlFetcher and integration libraries are written.
Cool, I'll check this out, thanks!

I am actually using UIL currently in my app but looking at options to move to Glide and all other parts have turned out trivial to replicate in Glide. This is just the little part of annoying wierdness you tend to have in your apps:)

All the best:
Harri

Róbert Papp

unread,
Aug 7, 2015, 7:00:31 AM8/7/15
to har...@gmail.com, Glide
Thanks for the clarification. Feel free to ask more questions if you're stuck with writing the Fetcher.
You can also search this forum or Glide issues on GitHub for the classnames, I'm sure there are some examples.

+Robi

har...@gmail.com

unread,
Aug 11, 2015, 4:14:22 AM8/11/15
to Glide, har...@gmail.com
Hei!

If anyone is interested I managed to get this working - I ended up using the request interceptors OkHttp has.

1) I included the OKHttp module, but made it so that it is not registered in the manifest (I do not want to use the default OkHttpUrlLoader.Factory but I need the OkHttpUrlLoader class and its OkHttpUrlLoader.Factory)
2) I added my own module to manifest that in registerComponents() method registered a very similar OkHttpUrlLoader.Factory with an OkHttpClient that has a custom interceptor.
3) In the interceptor I look at the URL's of the requests and if I detect that this request URL is the one I need to use with PUT then I swap the request for a new one with PUT instead of GET.

Not the most elegant solution, but I feel this way I do not have to worry that I change the Glide default functionality too much for the sake of one special request out of many normal ones.

All the best:
Harri
Reply all
Reply to author
Forward
0 new messages