What's the difference between the Bitcoin's peer to peer protocol and the RPC API? Bitcoin implements both a peer-to-peer synchronization protocol (normally on port 8333) and a JSON-RPC API (normally on port 8332).


What are these designed to accomplish?
If I'm trying to implement a wallet that doesn't need bitcoind to be installed to work, which one should I use?
What existing libraries implement the low-level details of these protocols?


Related:


What is the difference between the rpc port 8332 and port 8333?
The Peer to Peer protocol (using version, verack, getdata, ... etc. messages) is used by all clients communicating on the network. This protocol is how data is spread through the network. This is done directly over TCP/IP. Messages have their own format (not JSON) and allow the spread of transactions and blocks through the network. Read more at: https://bitcoin.org/en/developer-reference#protocol-versions. 

After a Bitcoin Core full node has received the block and transaction data via this P2P protocol, then a user can use the RPC interface to query the node about the data it has received. The JSON-RPC interface used is specific to Bitcoin Core, although other clients may introduce similar interfaces for ease of use. Nodes do not typically communicate with each other using the RPC interface at all, the RPC calls are more like tools that Bitcoin Core provides for developers to give them access to the blockchain data.