Listen to the beat and pay attention to its patterns. Fitting the rap rhyme vocabulary into the beat is the most challenging aspect. It has to be done in such a way so that it sounds natural and not forced.
Start laying down rhymes. What the words are don't actually matter, nor does it have to make any sense. By getting into the practice of creating rhymes and lines for the entire length of the song, you get the feel for the relationship between the words and the rhythm..
Write down words on paper while listening to songs and beats. Make use of a dictionary to help you find the right ones. Take your time. Writing rap is like writing poetry. Both take an economy of words and every word matters.
Rap along with the song using the words you wrote. You may find you need to edit your rap rhymes to get it just right. Once you've finished with one song, go on to the next. As you get better, you will find that you don't have to write down the words before rapping them -- they will just come to you.