Skip to content
This repository was archived by the owner on Jul 29, 2022. It is now read-only.

Add new functions that use HttpRequest and Try to eventually replace Fuel and Promises #55

Merged
merged 3 commits into from
May 7, 2021
Merged

Conversation

stevenzeck
Copy link
Contributor

@stevenzeck stevenzeck commented Apr 27, 2021

This PR creates new functions that use the DefaultHttpClient and Try to eventually replace the existing ones that use Fuel and Promises.

  • The two parseUrlString functions are the replacements for the parseURL ones (applicable to OPDS1Parser and OPDS2Parser)
  • Instead of accepting a URL, it accepts a String and an optional HttpClient (both)
  • retrieveOpenSearchTemplate is the replacement for fetchOpenSearchTemplate (OPDS1Parser)
  • For Instead of returning a Promise, it returns a Try (both)
  • parseURL and fetchOpenSearchTemplate are both marked as deprecated with a warning (both)
  • New function, parseRequest, that accepts an HttpRequest and an optional HttpClient
  • Deprecated functions use the DefaultHttpClient, replacing Fuel, thus removing Fuel as a dependency

I took the liberty of naming the new functions, but feel free to change them.

@stevenzeck stevenzeck changed the title Replace Fuel and Promises with new HttpRequest and Try Add new functions that use HttpRequest and Try to eventually Fuel and Promises Apr 27, 2021
@stevenzeck stevenzeck changed the title Add new functions that use HttpRequest and Try to eventually Fuel and Promises Add new functions that use HttpRequest and Try to eventually replace Fuel and Promises Apr 27, 2021
Copy link
Member

@mickael-menu mickael-menu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a stab at this! 🚀

@@ -45,13 +49,43 @@ object Namespaces {
class OPDS1Parser {
companion object {

suspend fun parseUrlString(url: String): Try<ParseData, Exception> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be interesting to take a client argument to let the app provide its own implementation if necessary.

Also an additional parseRequest() API taking directly an HttpRequest would let the app customize the HTTP headers, timeouts and other settings without a custom HttpClient. This way we don't need to provide parseUrlString(url: String, headers: MutableMap<String, String>).

Suggested change
suspend fun parseUrlString(url: String): Try<ParseData, Exception> {
suspend fun parseUrlString(url: String, client: HttpClient = DefaultHttpClient()): Try<ParseData, Exception> {
...
}
suspend fun parseRequest(request: HttpRequest, client: HttpClient = DefaultHttpClient()) ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can actually just have one function in that case: Accepts a URL as a string, and accepts an HttpClient with the default being DefaultHttpClient. And parseRequest sounds better than parseUrlString.

@qnga
Copy link
Member

qnga commented Apr 30, 2021

I wonder why you want to make HTTP requests inside a parser... Am I missing something?
Also, if the API is going to be freshened up, it might be the right time to enforce the new naming conventions: Opds2Parser, Opds1Parser.

@mickael-menu
Copy link
Member

I wonder why you want to make HTTP requests inside a parser... Am I missing something?

That's a good point. Down the line, I'd like to offer a more high-level API which would handle:

Some of these will need control over the HTTP requests.

But for this PR, I think the goal is mostly to keep feature parity with the existing implementation while deprecating Fuel and kovenant.

@stevenzeck
Copy link
Contributor Author

Yeah, this PR was about replacing Kovenant and Fuel. I just realized that the old functions that still use Fuel can actually use the new Http service, as long as they still use Kovenant to return a Promise. That will at least remove the need for Fuel though.

- Add an optional HttpClient to each new function
- Add a new function that accepts a HttpRequest
- Replace existing functions using Fuel to use new Http
@stevenzeck
Copy link
Contributor Author

@mickael-menu made the suggested changes.

@mickael-menu mickael-menu merged commit b345189 into readium:develop May 7, 2021
@mickael-menu
Copy link
Member

Thanks @stevenzeck!

@stevenzeck stevenzeck deleted the new-http-client branch May 9, 2021 20:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants