Getting the Wikipedia URL
Explore how to create a function that generates Wikipedia search URLs by appending user input. Learn to use Ramda's curried concat, pipe, and tap functions to build and test this URL constructor, enhancing your functional programming skills.
We'll cover the following...
As of this course, Wikipedia’s API search url is https://en.wikipedia.org/w/api.php?origin=*&action=opensearch&search=
For an actual search, append a topic. If you need bears, for example, the url looks like this:
https://en.wikipedia.org/w/api.php?origin=*&action=opensearch&search=bears
See? We just added bears to the end. Visiting that link returns JSON like this.
We’d like a function that takes a topic and returns the full Wikipedia search URL. As the user types we build the URL based off their input.
Here’s a nice start
I’d keep it this way, but this is a Ramda course! We want to get comfortable with using it, so how about this?
concat, true to its name, concatenates strings and arrays. It’s curried so providing the URL as one argument returns a function expecting a second string.
Let’s quickly test our code. It should be looking like this so far
Go ahead and update your index.js by importing our two functions, along with Ramda’s pipe and tap.
This new code’s constructing our request URL from the user’s input and logging it via tap.
Check it out.
We’ll be changing it again soon, but it’s nice to see our progress thus far!