Client and Server application in Rust

Hey all,

The requirement of my application is to develop a client that will convert a text file to json and send this file over the network to an http serve.

How can this task be implemented in Rust please

Breaking it down you need:

  1. To read the text file. You can use the standard library for that.
  2. Serialize it as json. You can use serde_json for that.
  3. Send the http request. You can use reqwest for that.

Hope that gives you a starting point.

2 Likes

It if it is small text file to be converted to json and sent over the network, so what is the best method? should I establish a TCP connection or should I use the upper level http protocol?

If it's not part of your requirements, then just don't. Stick to http.

1 Like

If you want to transfer data over a TCP/IP connection you need to wrap it up in some kind of protocol to make sure it goes correctly. Even if is a simple as announcing how many bytes is coming and then sending the bytes. Then you will need some response to indicate to the transmitter that the data was received OK or not.

You can invent your own protocol to do that. Or you can just use an existing one, like HTTP.

If you need any kind of security in the communication you can do that yourself with TLS or whatever. Or you can use a ready made solution like HTTPS.

Personally, unless I have to, I'm all for using ready made solutions. They are likely more widely used and tested than anything I can make for myself.

2 Likes