Summary: The first two chapters of the book of Joshua detail the preparation and ultimate entry into the Promised Land. Joshua dispatches two men, identified by the Midrash (Bamidbar Rabbah 16:1) to be Calev ben Yefuneh and Pinchas ben Elazar to spy out the area and city of Jericho. They arrive at the house of Rachav, whose house was built into the wall of the city.
After a tip off to the king of Jericho, Rachav protects the spies from danger, pleading with them to reciprocate by pledging to protect her and her family during the imminent battle. They agree and she ties a scarlet thread in the window to mark her location. After relating the incident to Joshua they declare that God has delivered the land to the Jewish people.
A deeper look: Rachav is described in the beginning of chapter two as a זוֹנָה(zonah). Rashi (d. 1105) explains this to mean an innkeeper while Radak (d. 1235) applies the usual translation of harlot. The Gemara ties the two concepts together, describing Rachav as a woman of exceptional beauty (Megillah 15a) who was indeed an innkeeper and was therefore visited by many of the leaders and monarchs (Zevachim 116b).
The Midrash relates that she repented and drew close to God (Bamidbar Rabbah 3:2). The Gemara further explains that Rachav converted and married Joshua (Megillah 14b). Tosafos raise an interesting questing that since the Jewish people were forbidden to marry into any of the Canaanite nations (Deuteronomy 7:3), how could Joshua have married her?
Two answers are proposed; Either Rachav and her family were in fact strangers living among the people of Jericho and were not from one of the seven Canaanite nations or if they were from one of the Canaanite nations, they converted before the Jewish people entered the Land of Israel, allowing Rachav to marry Joshua. Either way, to her merit the Gemara lists eight prophets who were descended from Rachav and Joshua including Jeremiah (ibid.).