What is the best way to make this work(ask multiple json apis)

Hello,

A lonng time ago I make a website in Ruby on Rails and I wanted to try if I can port it to Rust/Rocket.

I have to take these steps to make the website work

The NUMBER on step 3 and step 4 is the objectNumber I can find on step 2.

  1. ask this api for a respons : "https://www.rijksmuseum.nl/api/nl/collection?key=xxxx&format=json&type=schilderij&toppieces=True"
  2. get the ObjectNumber out of the respons. Schould be 10 strings.
  3. ask this api for more info on a objectNumber : "https://www.rijksmuseum.nl/api/nl/collection/NUMBER?key=xxxxx&format=json"
  4. ask this api for the images : "https://www.rijksmuseum.nl/api/nl/collection/NUMBER/tiles?key=xxxx&format=json".
  5. get some requested data out of 3 and 4 .
  6. display the image and the data.

What is the best way I can fetch and filter out the data I need and can step 3 and step 4 in parallel.

Regards,

Roelof

Hi!

There are a couple of crates you may use to approach this.

To perform the HTTP requests you could use the reqwest, library. It's been in development for a while and seems fairly stable.
Just a few days ago surf (see also here) was released by the rust async ergonomics working group. If you're feeling fancy you can have a go at that - although I'm not certain how async functions would work in rocket.
You could have a look at gotham too, which may piece together more nicely with async functions, as it's async itself, however I haven't used it yet.

To parse the data you obtain from these APIs you could use serde_json which together with serde can parse JSON into structs, or allows you to directly analyze a JSON value.

For performing both requests in parallel you can either use async or just launch two threads: see this example.

Now, in case you're just getting started with rust I would recommend to try out doing any one of these things in isolation first. Trying to do everything at once may be overwhelming at first. I think a good task for a beginner may be to attempt to make the requests, using the reqwest library and then parse them using serde_json.

Best,
ambiso

Edit:
note that surf and async-std might just not be ready enough yet.

Thanks, I will try to do it in very very small steps. Thanks for the pointers