Certificate pinning

Hello,
Is there any way to do certificate pinning to make sure my http requests are communicating to the right server? Thus avoiding man in the middle attacks.
I want to prevent someone from forging http requests. Any pointer on how to do that?
Thanks