goactions.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. {
  2. title: 'GoActions',
  3. crumbs: [
  4. { "User's Guide": '../users/' },
  5. ],
  6. }
  7. <h1>GoActions</h1>
  8. <p>The traditional Common Gateway Interface (CGI) is a slow technique for creating dynamic web pages
  9. because CGI processing results in the creation of a new process for every request. This is slow and cumbersome.
  10. GoAhead provides a high-performance replacement called GoActions&trade; that is a more suitable solution
  11. for embedded systems that demand compact and efficient solutions.</p>
  12. <p>GoActions are "C" language functions that are directly bound to specific URIs. They respond to client
  13. requests without creating a new process for each request. By sharing the address space with GoAhead, GoActions
  14. can directly access the full request context. GoActions are serviced by the <i>action</i> handler.</p>
  15. <h2>Defining GoActions</h2>
  16. <p>GoActions are defined by the
  17. <i><a href="../ref/api/goahead.html#group___webs_1gabadb35ad9084ca79783d0a63437d4959">websDefineAction</a></i> API.
  18. For example:</p>
  19. <pre class="ui code segment">
  20. static void buy(Webs *wp)
  21. {
  22. websSetStatus(wp, 200);
  23. websWriteHeaders(wp, 0, 0);
  24. websWriteEndHeaders(wp);
  25. websWrite(wp, "Name %s", websGetVar(wp, "name", ""));
  26. websWrite(wp, "Age %s", websGetVar(wp, "age", ""));
  27. websDone(wp);
  28. }
  29. <b>websDefineAction("buy", buy);</b>
  30. </pre>
  31. <h2>Calling GoActions</h2>
  32. <p>GoActions are bound to URIs that begin with <i>/action/</i>.
  33. When a client requests a URI <i>/action/NAME</i>, the action handler is invoked which then
  34. looks for a GoAction by NAME. The function bound to NAME is then is invoked to service the request. For
  35. example:</p>
  36. <pre class="ui code segment">
  37. /action/buy?name=John&amp;item=candy
  38. </pre>
  39. <p>This will invoke the GoAction <i>buy</i> which will run the bound C function. The action handler will
  40. automatically decode the query string "name=John&amp;age=30" and define GoAhead variables called "name" and "age".</p>
  41. <p>The GoAction is responsible for writing the HTTP header and HTML document content back to the user's
  42. browser.</p>