However, is it possible that a REST service use the TCP protocol for its communication? If yes, then will it violate its principles?
Short Answer
No it will not violate its principles if you write it according to REST principles. Yes it will violate its principles if you do not follow REST principles. Your code on the client and server side will have to obey REST rules. For example, if I send a "GET" to "...employee/22", it better send me a REST response e.g. 200, headers and content type etc. And doing all that will be basically doing what HTTP does.
Long Answer
The answer to your question is provided by @ГеоргиКременлиев. I actually think that might be the only correct answer.
It is true that REST is mostly tied to HTTP and when people speak about REST they're talking about HTTP. But, "mostly" does not mean "always" and even if it was "always" it still does not mean that REST is not possible without HTTP and that is pointed out in the links from @ГеоргиКременлиев answer. HTTP worked so well (Client and Server), the principles were taken to create any client/server application with those principles so they can enjoy the same benefits as HTTP. In other words,
- Any client can be designed to understand REST (For example, browsers understand REST)
- Any server can be designed to understand REST (For example, web servers understand REST)
Here is an important bit, REST principles were borrowed from HTTP. Therefore, if you are RESTful, it means you are following HTTP principles.
Having said that, if you do not want to use HTTP, then your client and/or server both have to understand the same language that HTTP speaks. For example, it uses verbs such as GET, POST, PUT etc. and response codes such as 200, 300, 400, and so on. Therefore, your server needs to understand how to respond to a request such as ...employee/22 and return:
- 200 OK, 301 moved permanently, 500 etc...
- Content-Type
- other headers needed
Your client also needs to understand those headers to be able to send requests to the server and consume responses from the servers.
And if you do implement all this, and security (authentication and authorization etc.), and chaching and the list goes on, you will realize you are just trying to re-invent the wheel: HTTP.
Is that worth it? Are you sure the bottleneck regarding performance was the HTTP protocol or was it your backend code, the queries to the database etc?