{"size": 2053, "ext": "scrbl", "max_stars_repo_path": "web-server-doc/web-server/scribblings/servlet.scrbl", "max_stars_repo_name": "jessealama/web-server", "max_stars_repo_stars_event_min_datetime": "2015-01-21T08:11:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T08:28:39.000Z", "max_issues_repo_path": "web-server-doc/web-server/scribblings/servlet.scrbl", "max_issues_repo_name": "jessealama/web-server", "max_issues_repo_issues_event_min_datetime": "2015-01-14T08:06:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T14:38:40.000Z", "max_forks_repo_path": "web-server-doc/web-server/scribblings/servlet.scrbl", "max_forks_repo_name": "jessealama/web-server", "max_forks_repo_forks_event_min_datetime": "2015-03-05T15:07:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-30T18:59:25.000Z"}
{"max_stars_count": 82, "max_issues_count": 105, "max_forks_count": 37, "avg_line_length": 33.6557377049, "max_line_length": 139, "alphanum_fraction": 0.7043351193}
#lang scribble/doc
@(require "web-server.rkt")

@title[#:tag "servlet"]{Stateful Servlets}

@defmodule[web-server/servlet]

@section[#:style 'hidden #:tag "servlet-example"]{Example}

A stateful servlet should @racket[provide] the following exports:

@(require (for-label web-server/http
                     (except-in web-server/managers/manager manager)
                     "dummy-v2-servlet.rkt")) @; to give a binding context
@declare-exporting[#:use-sources (web-server/scribblings/dummy-v2-servlet)]

@defthing[interface-version (one-of/c 'v2)]{
 This indicates that the servlet is a version two servlet.
}

@defthing[manager manager?]{
 The @tech{manager} for the continuations of this servlet. See @secref["managers"] for options.
}

@defproc[(start [initial-request request?])
         can-be-response?]{
 This function is called when an instance of this servlet is started.
 The argument is the HTTP request that initiated the instance.
}

An example version 2 module:
@(require (for-label web-server/managers/none))
@racketmod[
 racket
 (require web-server/http
          web-server/managers/none)
 (provide interface-version manager start)
 
 (define interface-version 'v2)
 (define manager 
   (create-none-manager
    (lambda (req)
      (response/xexpr
       `(html (head (title "No Continuations Here!"))
              (body (h1 "No Continuations Here!")))))))
 (define (start req)
   (response/xexpr
    `(html (head (title "Hello World!"))
           (body (h1 "Hi Mom!")))))
 ]

These servlets have an extensive API available to them: @racketmodname[net/url], @racketmodname[web-server/http],
      @racketmodname[web-server/http/bindings], @racketmodname[web-server/servlet/servlet-structs], @racketmodname[web-server/servlet/web],
      @racketmodname[web-server/servlet/web-cells], and @racketmodname[web-server/dispatch].
      Some of these are documented in the subsections that follow.

@include-section["contracts.scrbl"]
@include-section["web.scrbl"]
@include-section["web-cells.scrbl"]
@include-section["managers.scrbl"]
