Following the 4-2 win over Sunderland on the opening day of the season, Ranieri took his side to East London to take on a Hammers side which surprisingly beat Arsenal.
Slaven Bilic's side were in high spirits following that victory, but found themselves behind on 27 minutes as Shinji Okazaki opened his Premier League account from close range.
Just 11 minutes later, the Foxes made it 2-0 as Riyad Mahrez - who ripped Sunderland apart last weekend - continued his stunning form with the second goal.
West Ham were harshly denied a penalty on the stroke of half time as Diafra Sakho was brought down by Kasper Schmeichel, but new signing Dimitri Payet did pull one back for the Hammers in the second half.
The Hammers couldn't find the equaliser late on, and as goalkeeper Adrian was brought up for a corner kick, the Spaniard was sent off for a high foot, leaving defender Carl Jenkinson to go in goal.
Leicester held on for the victory, making it two wins from two games for Ranieri, who is enjoying a real honeymoon period with the Foxes - whilst Bilic is still searching for his first home win as West Ham boss.