Joseph Haydn was a musician all his life. At first he was going to be a singer -- in a cathedral in Vienna, where he would later die on May 31, 1809 -- and did sing from 1740 to 1750, when he was eighteen (he was born on March 31,1732, in Rohrau). Afterwards he continued to work as a musician, playing violin, keyboard, and other instruments as a free-lance. He also gave music lessons, especially singing lessons, and wrote music -- much like many other musicians, he worked to make ends meet, from day to day.
It's interesting because this was at the time that was the last period when most musicians effectively were servants to nobles, while he was free-lancing. By 1759, he was doing this, having been "appointed" to be Count Morzin's musical director. By 1762, he was in charge of a small group -- fifteen to twenty -- of musicians, and wrote music as his employer, Prince Nikolaus Esterházy, commanded him to.
Haydn's music writing changed over time. In his early years, he wrote mostly instrumental music, symphonies, etc. There were concerts almost twice a week, and Haydn was a really busy man -- composing 125 trios in ten years along with all his other work. In 1768, after the opening of a new opera house in Eszterháza, opera music became more important, along with church music. Before 1770, Haydn's music was for simple entertainment, but around this time one sees that he was widening his horizons towards more original pieces. During this time he wrote a bunch of operas, such as Lo speziale, L'infedeltà delusa (1773) and Il mondo della luna (1777). In the 1780s, he worked on piano sonatas, piano trios, symphonies, string quartets, and more.
As his life progressed, Haydn's pieces grew in originality, freedom of style, and also humor. When Nikolaus Esterházy died in 1790, after twenty-eight years of employment, he was retained by Esterházy's son, but was allowed to travel. He visited London, lived in Vienna, and composed. When he returned from traveling, he resumed work for Nikolaus Esterházy's grandson (the son who he had taken up work for had already died) and wrote masses.
Over time, we see Haydn getting more and more free with his work -- it's a parallel, almost, with the way that people were with their rulers at the time. During his lifetime, which ended in 1809, the American and French revolutions took place. As he worked originally just for his employer's musical entertainment, to writing masses and traveling, he experienced this freedom. And in the end his music was better for it; and brought on a newer age of music as people began to feel more free to express themselves musically, and the 1800s came on.