title: ServiceStack Request Body
body: <p>I am trying to write my 1st REST service in servicestack and ormlite. It's not going too bad.</p>
  
  <p>I have managed to write the code that displays all records, records based on and ID and delete a record based on an ID.</p>
  
  <p>Now I am moving onto adding and editing a record and I am getting confused about how to get the data from the request body of the call.</p>
  
  <p>I am doing a</p>
  
  <pre><code>POST: http://localhost:7571/equipment/create/123
  </code></pre>
  
  <p>with the request body of</p>
  
  <pre><code>[{"eMCo":"1","equipment":"DP112","location":"Field","manufacturer":"","model":"","modelYr":"2013","vinNumber":"","description":"Trevor","status":"A","attachToEquip":"BR118","licensePlateNo":""}]
  </code></pre>
  
  <p>But in my service I cannot work out how to access the request body data in this function:</p>
  
  <pre><code>public object Post(EMEMTrev request)
      {
          var dbFactory = new OrmLiteConnectionFactory("Data Source=(local);Initial Catalog=Kent;Integrated Security=True", SqlServerDialect.Provider);
          using (IDbConnection db = dbFactory.OpenDbConnection())
          {
              //base.Request.FormData[""]
              db.Insert(request);
          }
          return null;
      }
  </code></pre>
  
  <p>Here is the complete code... If you can point out ANYTHING I am doing wrong please do !</p>
  
  <pre><code>using ServiceStack;
  using ServiceStack.OrmLite;
  using System;
  using System.Collections.Generic;
  using System.Data;
  using System.Linq;
  using System.Web;
  
  namespace ViewPoint
  {
  [Api("Enables viewiing, creation, updating and deletion of equipment from the EMEM table.")]
  [Route("/equipment", "GET")]
  [Route("/equipment/detail/{equipment}", "GET")]
  [Route("/equipment/delete/{equipment}", "DELETE")]
  [Route("/equipment/update/{equipment}", "PATCH")]
  [Route("/equipment/create/{equipment}", "POST")]
  
  public class EMEMTrev
  {
      public string eMCo { get; set; }
      public string equipment { get; set; }
      public string Location { get; set; }
      public string Manufacturer { get; set; }
      public string Model { get; set; }
      public string ModelYr { get; set; }
      public string VINNumber { get; set; }
      public string Description { get; set; }
      public string Status { get; set; }
      public string AttachToEquip { get; set; }
      public string LicensePlateNo { get; set; }
  }
  
  public class EMEMTrevResponse
  {
      public string eMCo { get; set; }
      public string equipment { get; set; }
      public string Location { get; set; }
      public string Manufacturer { get; set; }
      public string Model { get; set; }
      public string ModelYr { get; set; }
      public string VINNumber { get; set; }
      public string Description { get; set; }
      public string Status { get; set; }
      public string AttachToEquip { get; set; }
      public string LicensePlateNo { get; set; }
      public ResponseStatus ResponseStatus { get; set; } //Where Exceptions get auto-serialized
  }
  
  
  public class EquipmentService : Service
  {
      public object Get(EMEMTrev request)
      {
          var dbFactory = new OrmLiteConnectionFactory("Data Source=(local);Initial Catalog=Kent;Integrated Security=True", SqlServerDialect.Provider);
          using (IDbConnection db = dbFactory.OpenDbConnection())
          {
              if (request.equipment == null)
              {
                  List&lt;EMEMTrev&gt; results = db.Select&lt;EMEMTrev&gt;();
                  return results;
              }
              else
              {
                  List&lt;EMEMTrev&gt; results = db.Select&lt;EMEMTrev&gt;(p =&gt; p.Where(ev =&gt; ev.equipment == request.equipment));
                  return results;
              }
  
          }
      }
      public object Delete(EMEMTrev request)
      {
          var dbFactory = new OrmLiteConnectionFactory("Data Source=(local);Initial Catalog=Kent;Integrated Security=True", SqlServerDialect.Provider);
          using (IDbConnection db = dbFactory.OpenDbConnection())
          {
              db.Delete&lt;EMEMTrev&gt;(p =&gt; p.Where(ev =&gt; ev.equipment == request.equipment));
          }
          return null;
      }
  
      public object Post(EMEMTrev request)
      {
          var dbFactory = new OrmLiteConnectionFactory("Data Source=(local);Initial Catalog=Kent;Integrated Security=True", SqlServerDialect.Provider);
          using (IDbConnection db = dbFactory.OpenDbConnection())
          {
              //base.Request.FormData[""]
              db.Insert(request);
          }
          return null;
      }
  
      public object Patch(EMEMTrev request)
      {
          var dbFactory = new OrmLiteConnectionFactory("Data Source=(local);Initial Catalog=Kent;Integrated Security=True", SqlServerDialect.Provider);
          using (IDbConnection db = dbFactory.OpenDbConnection())
          {
              db.Update(request);
          }
          return null;
      }
  }
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATED CODE:</strong></p>
  
  <p>ServiceEquipment.cs</p>
  
  <pre><code>using ServiceStack;
  using ServiceStack.OrmLite;
  using System;
  using System.Collections.Generic;
  using System.Data;
  using System.Linq;
  using System.Net;
  using System.Web;
  
  namespace ViewPoint
  {
  [Api("Enables viewiing, creation, updating and deletion of equipment from the EMEM table. Use a POST to create an EMEM or a PUT to update one.")]
  [Route("/equipment", "GET,POST,PUT")]
  [Route("/equipment/{equipment}", "GET,DELETE")]
  
  public class EMEMTrev
  {
          public string eMCo { get; set; }
          public string equipment { get; set; }
          public string location { get; set; }
          public string manufacturer { get; set; }
          public string model { get; set; }
          public string modelYr { get; set; }
          public string vinNumber { get; set; }
          public string description { get; set; }
          public string status { get; set; }
          public string attachToEquip { get; set; }
          public string licensePlateNo { get; set; }
  
  }
  
  public class EMEMTrevResponse
  {
      public EMEMTrev emem { get; set; }
      public ResponseStatus ResponseStatus { get; set; } //Where Exceptions get auto-serialized
  }
  
  
  public class EquipmentService : Service
  {
      public object Get(EMEMTrev request)
      {
          var dbFactory = new OrmLiteConnectionFactory("Data Source=(local);Initial Catalog=Kent;Integrated Security=True", SqlServerDialect.Provider);
                      using (IDbConnection db = dbFactory.OpenDbConnection())
          {
              if (request == null)
              {
                  List&lt;EMEMTrev&gt; results = db.Select&lt;EMEMTrev&gt;();
                  return results;
              }
              else
              {
                  List&lt;EMEMTrev&gt; results = db.Select&lt;EMEMTrev&gt;(p =&gt; p.Where(ev =&gt; ev.equipment == request.equipment));
  
                  return results;
              }
  
          }
      }
      public object Delete(EMEMTrev request)
      {
          var dbFactory = new OrmLiteConnectionFactory("Data Source=(local);Initial Catalog=Kent;Integrated Security=True", SqlServerDialect.Provider);
          using (IDbConnection db = dbFactory.OpenDbConnection())
          {
              db.Delete&lt;EMEMTrev&gt;(p =&gt; p.Where(ev =&gt; ev.equipment == request.equipment));
          }
          return new HttpResult
          {
              StatusCode = HttpStatusCode.NoContent,
              Headers =
                             {
                                 {HttpHeaders.Location, this.Request.AbsoluteUri.CombineWith(request.equipment)}
                             }
          };
      }
  
      public object Post(EMEMTrev request)
      {
          var dbFactory = new OrmLiteConnectionFactory("Data Source=(local);Initial Catalog=Kent;Integrated Security=True", SqlServerDialect.Provider);
          using (IDbConnection db = dbFactory.OpenDbConnection())
          {
              db.Insert(request);
          }
          return new HttpResult()
          {
              StatusCode = HttpStatusCode.Created,
              Headers =
                             {
                                 {HttpHeaders.Location, base.Request.AbsoluteUri.CombineWith(request.equipment)}
                             }
          };
      }
  
      public object Put(EMEMTrev request)
      {
          var dbFactory = new OrmLiteConnectionFactory("Data Source=(local);Initial Catalog=Kent;Integrated Security=True", SqlServerDialect.Provider);
          using (IDbConnection db = dbFactory.OpenDbConnection())
          {
              db.Update(request);
          }
          return new HttpResult
          {
              StatusCode = HttpStatusCode.NoContent,
              Headers =
                             {
                                 {HttpHeaders.Location, base.Request.AbsoluteUri.CombineWith(request.equipment)}
                             }
          };
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>AppHost.cs:</p>
  
  <pre><code>using System.Configuration;
  using ServiceStack;
  using ServiceStack.Auth;
  using ServiceStack.Configuration;
  using ServiceStack.Data;
  using ServiceStack.OrmLite;
  
  [assembly: WebActivator.PreApplicationStartMethod(typeof(ViewPoint.App_Start.AppHost), "Start")]
  
  
  /**
  * Entire ServiceStack Starter Template configured with a 'Hello' Web Service and a 'Todo' Rest Service.
  *
  * Auto-Generated Metadata API page at: /metadata
  * See other complete web service examples at: https://github.com/ServiceStack/ServiceStack.Examples
  */
  
  namespace ViewPoint.App_Start
  {
  public class AppHost : AppHostBase
  {       
      public AppHost() //Tell ServiceStack the name and where to find your web services
          : base("StarterTemplate ASP.NET Host", typeof(EquipmentService).Assembly) { }
  
      public override void Configure(Funq.Container container)
      {
          //Set JSON web services to return idiomatic JSON camelCase properties
          ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
  
          //Configure User Defined REST Paths
          //Routes
          //  .Add&lt;Hello&gt;("/hello")
          //  .Add&lt;Hello&gt;("/hello/{Name*}");
  
          //Uncomment to change the default ServiceStack configuration
          //SetConfig(new HostConfig {
          //});
  
          //Enable Authentication
          //ConfigureAuth(container);
  
          //Register all your dependencies
          //container.Register(new TodoRepository());         
      }
  
      /* Example ServiceStack Authentication and CustomUserSession */
      private void ConfigureAuth(Funq.Container container)
      {
          var appSettings = new AppSettings();
  
          //Default route: /auth/{provider}
          Plugins.Add(new AuthFeature(() =&gt; new CustomUserSession(),
              new IAuthProvider[] {
                  new CredentialsAuthProvider(appSettings), 
                  new FacebookAuthProvider(appSettings), 
                  new TwitterAuthProvider(appSettings), 
                  new BasicAuthProvider(appSettings), 
              })); 
  
          //Default route: /register
          Plugins.Add(new RegistrationFeature()); 
  
          //Requires ConnectionString configured in Web.Config
          var connectionString = ConfigurationManager.ConnectionStrings["AppDb"].ConnectionString;
          container.Register&lt;IDbConnectionFactory&gt;(c =&gt;
              new OrmLiteConnectionFactory(connectionString, SqlServerDialect.Provider));
  
          container.Register&lt;IUserAuthRepository&gt;(c =&gt;
              new OrmLiteAuthRepository(c.Resolve&lt;IDbConnectionFactory&gt;()));
  
          container.Resolve&lt;IUserAuthRepository&gt;().InitSchema();
      }
  
      public static void Start()
      {
          new AppHost().Init();
      }
  }
  </code></pre>
  
  <p>}</p>