Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. component
  2. restpath = "test/people/"
  3. rest = true
  4. {
  5. remote void function create(
  6. required string first_name restargsource = "Form",
  7. required string last_name restargsource = "Form"
  8. )
  9. httpmethod = "POST"
  10. restpath = ""
  11. produces = "application/json"
  12. {
  13. // Simulate adding person to database.
  14. ArrayAppend(
  15. Application.people,
  16. { "first_name" = first_name, "last_name" = last_name }
  17. );
  18.  
  19. // Simulate getting people from database.
  20. var people = Application.people;
  21.  
  22. restSetResponse( {
  23. "status" = 201,
  24. "content" = SerializeJSON( people )
  25. } );
  26. }
  27. }
  28.  
  29. httpService = new http(method = "POST", url = "https://localhost/rest/test/people");
  30. httpService.addParam( name = "first_name", type = "formfield", value = "Alice" );
  31. httpService.addParam( name = "last_name", type = "formfield", value = "Adams" );
  32. result = httpService.send().getPrefix();
  33.  
  34. <cfscript>
  35. Application.people = [];
  36.  
  37. people = new restmapping.test.People();
  38.  
  39. people.create( "Alice", "Adams" );
  40.  
  41. WriteDump( application.people );
  42. </cfscript>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement