title: Get the output of RestSetResponse without making HTTP request
body: <p>I have a minimal (example) REST end-point <code>test/people.cfc</code>:</p>
  
  <pre><code>component
    restpath = "test/people/"
    rest     = true
  {
    remote void function create(
      required  string   first_name restargsource = "Form",
      required  string   last_name  restargsource = "Form"
    )
      httpmethod  = "POST"
      restpath    = ""
      produces    = "application/json"
    {
      // Simulate adding person to database.
      ArrayAppend(
        Application.people,
        { "first_name" = first_name, "last_name" = last_name }
      );
  
      // Simulate getting people from database.
      var people = Application.people;
  
      restSetResponse( {
        "status"  = 201,
        "content" = SerializeJSON( people )
      } );
    }
  }
  </code></pre>
  
  <p>As noted <a href="https://stackoverflow.com/questions/15711287/coldfusion-10-rest-api-how-to-set-status-code-201-without-restsetresponse">here</a> and in the <a href="https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-m-r/restsetresponse.html" rel="nofollow noreferrer">ColdFusion documentation</a>:</p>
  
  <blockquote>
    <p>Note: ColdFusion ignores the function's return value and uses the response set using the <code>RestSetResponse()</code> function.</p>
  </blockquote>
  
  <p>So the <code>void</code> return type for the function appears to be correct for the REST function.</p>
  
  <p>Now, I know I can call it from a CFM page using:</p>
  
  <pre><code>httpService = new http(method = "POST", url = "https://localhost/rest/test/people"); 
  httpService.addParam( name = "first_name", type = "formfield", value = "Alice" ); 
  httpService.addParam( name = "last_name",  type = "formfield", value = "Adams" ); 
  result = httpService.send().getPrefix();
  </code></pre>
  
  <p>However, I would like to call the function without making a HTTP request.</p>
  
  <p>Firstly, the REST CFCs do not appear to be accessible from within the REST directory. This can be solved simply by creating a mapping in the ColdFusion admin panel to the root path of the REST service.</p>
  
  <p>I can then do:</p>
  
  <pre><code>&lt;cfscript&gt;
  Application.people = [];
  
  people = new restmapping.test.People();
  
  people.create( "Alice", "Adams" );
  
  WriteDump( application.people );
  &lt;/cfscript&gt;
  </code></pre>
  
  <p>This calls the function directly and the output shows it has added the person. However, the response from the REST function has disappeared into the aether. Does anyone know if it is possible to retrieve the response's HTTP status code and content (as a minimum - preferably all the HTTP headers)?</p>
  
  <p><strong>Update - Integration Testing Scenario</strong>:</p>
  
  <p>This is one use-case (of several) where calling the REST end-point via a HTTP request has knock-on effects that can be mitigated by invoking the end-point directly as a method of a component.</p>
  
  <pre><code>&lt;cfscript&gt;
  // Create an instance of the REST end-point component without
  // calling it via HTTP request.
  endPoint = new restfiles.test.TestRESTEndPoint();
  
  transaction {
    try {
      // Call a method on the end-point without making a HTTP request.
      endPoint.addValueToDatabase( 1, 'abcd' );
      assert( getRESTStatusCode(), 201 );
      assert( getRESTResponseText(), '{"id":1,"value":"abcd"}' );
      // Call another method on the end-point without making a HTTP request.
      endPoint.updateValueInDatabase( 1, 'dcba' );
      assert( getRESTStatusCode(), 200 );
      assert( getRESTResponseText(), '{"id":1,"value":"dcba"}' );
      // Call a third method on the end-point without making a HTTP request.
      endPoint.deleteValueInDatabase( 1 );
      assert( getRESTStatusCode(), 204 );
      assert( getRESTResponseText(), '' );
    }
    catch ( any e )
    {
      WriteDump( e );
    }
    finally
    {
      transaction action="rollback";
    }
  }
  &lt;/cfscript&gt;
  </code></pre>
  
  <p>Calling each REST function via a HTTP request will commit the data to the database after each request - cleaning up between tests where the data has been committed can get very complicated and often results in needing to flashback the database to a previous state (resulting in integration tests being unable to be run in parallel with any other tests and periods of unavailability during flashbacks). Being able to call the REST end-points without making lots of atomic HTTP requests and instead bundle them into a single transaction which can be rolled back means the testing can be performed in a single user's session.</p>
  
  <p>So, how can I get the HTTP status code and response text which have been set by <code>RestSetResponse()</code> when I create an instance of the REST component and invoke the function representing the REST path directly (without using a HTTP request)?</p>