title: Rust + Rocket: How I do read POST body from request as string?
body: <p>I'm building a simple REST API using Rust and Rocket.  One of the endpoints accepts a POST method request, and reads a large string from the request body.  I can't figure out how to do this with Rocket.</p>
  <p>The documentation describes how to read a JSON object from the body of a POST request, as well as how to read multipart form-data, but not a raw string.  Does anyone know how to do this?</p>
  <hr />
  <p><strong>Update:</strong></p>
  <p>Following the advice in Dave's answer below, I implemented the FromDataSimple trait to try to parse the request body.  This is what I've implemented, but it has only resulted in getting a &quot;404 Not Found&quot; response:</p>
  <pre><code>struct Store {
      contents: String,
  }
  
  impl FromDataSimple for Store {
      type Error = String;
  
      fn from_data(req: &amp;Request, data: Data) -&gt; data::Outcome&lt;Self, String&gt; {
          let mut contents = String::new();
  
          if let Err(e) = data.open().take(256).read_to_string(&amp;mut contents) {
              return Failure((Status::InternalServerError, format!(&quot;{:?}&quot;, e)));
          }
  
          Success(Store { contents })
      }
  }
  
  #[post(&quot;/process&quot;, format = &quot;application/json&quot;, data = &quot;&lt;input&gt;&quot;)]
  fn process_store(input: Store) -&gt; &amp;'static str {
      &quot;200 Okey Dokey&quot;
  }
  </code></pre>
  <p>Unfortunately when I run this and then ping it with the following request, I just get a 404 Not Found response :-(</p>
  <pre><code>curl -X POST -H &quot;Content-Type: application/json&quot; --data &quot;{ \&quot;contents\&quot;: \&quot;testytest\&quot;}&quot;  http://localhost:8080/process
  </code></pre>
  <hr />
  <p><strong>Update 2:</strong></p>
  <p>Actually this does work, I just forgot the mount the method into the routing handlers:</p>
  <pre><code>fn main() {
      rocket::ignite().mount(&quot;/&quot;, routes![index, process_store]).launch();
  }
  </code></pre>