Wiring a light switch in the middle of a circuit is necessary if there is more than one receptacle on the circuit but the light in question is not at the end. A circuit is one large loop with power going out to the various outlets, lights, and other fixtures through the hot wire and returning to the source through the neutral wire. In the course of this loop, the circuit can be isolated in parts and make smaller loops. This is the basic idea of how a switch can be wired to control a light or outlet while power is allowed to flow beyond it unhindered. In this instance, power will flow through the light and its switch which you will install. Hence, it is in the middle of the circuit.
Step 1 - Affix Switch Box and Lightbox
The job starts with the placement of the lightbox and the switch box. Determine this and affix the plastic boxes in their respective locations. The light box in a room is typically on the ceiling, but it does not have to be. The switch box should be placed at a comfortable level near the entrance to the room. Both may have preset nails to attach them. If not, attach them to the frame with nails or screws.
Step 2 - Feed Romex Through Light Box
Make sure the individual circuit is turned off before you begin working. Test it with a voltmeter to be sure. At the light box, cut the Romex cable and give yourself plenty to work with. Strip the insulation off of both ends at least 6 inches and separate the wires in each end.
Step 3 - Wire the Hot Connection
With the extra Romex, remove a length of white wire (enough to reach from the lightbox to the switch with wiggle room) and mark each end with black electrical tape. With a single wire nut, connect the black wire from the power source, the black wire leading to the next outlet, and the white wire with the black tape in what is called a pigtail. Run the white wire marked black to the switch and connect it to the lower brass or gold screw on the switch. Take a length of black wire and connect one end to the hot end of the light fixture and the other end to the top brass screw on the switch.
Step 4 - Wire Neutral Wires
With another single wire nut, make another pigtail connection between the neutral (white) wires coming from the power source, the white wire from the light fixture, and the white wire leading to the next outlet. To make a pigtail, strip an inch of the insulation off the wires, twist them together and screw on the wire nut.
Step 5 - Wire Ground Wires
Connect the ground (bare copper or green) wires from the power source, the next outlet, and switch with one final wire nut. Again, use the pigtail connection. Plastic light boxes and switch boxes require no further grounding. If you have a metal box, connect a fourth ground wire and attach it to the provided screw on the box. Nowadays plastic is mainly used, so in this case the fourth wire is not necessary.
If everything was wired as planned and the connections are good, you should be able to turn the circuit back on, and the switch should work to turn the light on and off. Even when off, power should flow to the next outlet down.