I used a Sonoff basic unit, which simplifies the wiring dramatically, as it combines a relay, an ESP8266 and a low voltage power supply into a single device. The device takes in mains voltage on the input side (typically 110V in the U.S.), and delivers that same voltage to the output side when the relay is switched on. There are several tutorials online that show how to program the Sonoff, but if you have any trouble, let me know, and I'll post instructions for that, too.
WARNING Be sure to turn off the power at the circuit breaker or fuse box before you try any of this.
So there are a few different ways that you could wire this. If you just wanted to replace a wall switch with a Sonoff, the connections are identical to that of the switch. The wall switch has two wires originating at the circuit breaker box that enter it. Another two wires exit the switch, and terminate at the socket or outlet that is being switched. Just remove the wires from the switch, and make the same connections to the Sonoff. The wires are normally black and white. The black is the so-called "hot" wire, and the white one is "neutral." They're marked with L and N, respectively, on the connection points of the Sonoff. There may be a green ground wire in the junction box, as well, but we can ignore it. You simply take the black and white wires that come from the circuit breaker, and connect them to the input side of the Sonoff, and connect the two wires that go to the outlet or lamp socket, and connect them to the output side of the Sonoff. That's it.
Now, for my ceiling lamp, I did things slightly differently. I wanted the wall switch to remain in place, and to still be usable in case the wifi was out. For this, I placed the Sonoff unit in the ceiling electrical box that holds up my pendant lamp. The wiring was the same as in the previous instructions, only this time, the black and white wires coming from the wall switch were attached to the input side of the Sonoff, and the wires going to the pendant lamp were attached to the output side. For this type of connection, use the most recent variation of the code, which turns the relay on before it attempts to connect to the wifi.
The Sonoff can be found on Ebay or here: