### Method

# Soup Server add_handler

#### Declaration [src]

    void
    soup_server_add_handler (
      SoupServer* server,
      const char* path,
      SoupServerCallback callback,
      gpointer user_data,
      GDestroyNotify destroy
    )

#### Description [src]

Adds a handler to `server` for requests prefixed by `path`.

If `path` is `NULL` or “/”, then this will be the default handler for all requests that don’t have a more specific handler. (Note though that if you want to handle requests to the special “” URI, you must explicitly register a handler for “”; the default handler will not be used for that case.)

For requests under `path` (that have not already been assigned a status code by a `SoupAuthDomain`, an early server handler, or a signal handler), `callback` will be invoked after receiving the request body; the `SoupServerMessage`‘s method, request-headers, and request-body properties will be set.

After determining what to do with the request, the callback must at a minimum call `soup_server_message_set_status()` on the message to set the response status code. Additionally, it may set response headers and/or fill in the response body.

If the callback cannot fully fill in the response before returning (eg, if it needs to wait for information from a database, or another network server), it should call `soup_server_message_pause()` to tell `server` to not send the response right away. When the response is ready, call `soup_server_message_unpause()` to cause it to be sent.

To send the response body a bit at a time using “chunked” encoding, first call `soup_message_headers_set_encoding()` to set `SOUP_ENCODING_CHUNKED` on the response-headers. Then call `soup_message_body_append()` (or `soup_message_body_append_bytes()`)) to append each chunk as it becomes ready, and `soup_server_message_unpause()` to make sure it’s running. (The server will automatically pause the message if it is using chunked encoding but no more chunks are available.) When you are done, call `soup_message_body_complete()` to indicate that no more chunks are coming.

#### Parameters

`path`

  Type: `const char*`

  The toplevel path for the handler.

  The argument can be `NULL`.
  The data is owned by the caller of the method.
  The value is a NUL terminated UTF-8 string.

`callback`

  Type: `SoupServerCallback`

  Callback to invoke for requests under `path`.

`user_data`

  Type: `gpointer`

  Data for `callback`.

  The argument can be `NULL`.
  The data is owned by the caller of the method.

`destroy`

  Type: `GDestroyNotify`

  Destroy notifier to free `user_data`.