What would be a good unidirectional wifi transmitter receiver?
I want to be able to talk with a wifi router roughly 20 metres away through two walls, without letting the signal spread in the unnecessary directions.
There are many descriptions, such as from Jacob Salmela and Instructables, but the key ingredients are a food can of appropriate dimension, a bit of coaxial cable and a connector suitable for your PC or phone.
Fine-tuning the antenna, both in aim it and in adjustment of the radiating element, is helpful. Use a real-time display of signal strength with applications such as wavemon on Linux or inSSIder for Windows.
without letting the signal spread in the unnecessary directions
you mostly want a directional or sector type of antenna, or a dish antenna. Step 1 is choosing directional or omnidirectional, you want some type of directional antenna.
you would need a compatible type wifi card or desktop/rack sitting type of switch/router that offers a remote wired antenna connection via coax cable.
wifi6 or 802.11ax now runs in the 6ghz frequency range, 802.11ac in both the 2.4ghz and 5ghz spectrum, the old 802.11g in 2.4ghz only. So you would need to identify the type of wifi you are using and choose the antenna that supports your wifi's frequency or frequencies.
given the saturation of wifi everywhere, doing a directional antenna like you describe is a good thing, and pretty simple if it's between two simple and relatively small locations or rooms within a building. You want to look at the radiation pattern of the antenna and do basic trig and distance math to see if it will over coverage where you want it given the narrowness of its beam. As for dBi gain that you need I can't help other than say look for ones with higher numbers, and 20 meters is not far but it depends on the materials that need to be penetrated. And putting a directional antenna at location A but not at location B to talk back through the walls won't help, so you will need antennas at both locations in which case you could choose ones with a vary narrow beam but high gain which would reduce signal spread in unnecessary directions. A web search on such hardware you should quickly recognize credible products and sellers, some being sold on amazon/ebay do work but you take your chances on those ones.
A call/email to a credible seller or manufacturer of such antennas you would want to do and get their recommendation before buying, they will know all the questions that you need to answer and help guide you to buy something that suits your needs.