Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
d4eae0e2
Commit
d4eae0e2
authored
Dec 10, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added minimalistic example
parent
4d7ea04d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
6 deletions
+32
-6
API.md
docs/API.md
+32
-6
No files found.
docs/API.md
View file @
d4eae0e2
...
@@ -6,13 +6,39 @@ Embedding Mongoose is done in two steps:
...
@@ -6,13 +6,39 @@ Embedding Mongoose is done in two steps:
[
mongoose.c
](
https://raw.github.com/cesanta/mongoose/master/mongoose.c
)
and
[
mongoose.c
](
https://raw.github.com/cesanta/mongoose/master/mongoose.c
)
and
[
mongoose.h
](
https://raw.github.com/cesanta/mongoose/master/mongoose.h
)
[
mongoose.h
](
https://raw.github.com/cesanta/mongoose/master/mongoose.h
)
to your application's source tree and include these two files in the build.
to your application's source tree and include these two files in the build.
2.
Somewhere in the application code, call
`mg_
start()`
to start the server.
2.
Somewhere in the application code, call
`mg_
create_server()`
to create
Pass configuration options and event handlers to
`mg_start()`
. Call
a server, configure it with
`mg_set_option()`
and loop with
`mg_
stop()`
when server needs to be stopped
.
`mg_
poll_server()`
until done. Call
`mg_destroy_server()`
to cleanup
.
Mongoose calls event handlers when certain events happen.
Here's minimal application, suppose it is in the
`minimal.c`
file:
For example, when new request arrives, Mongoose calls
`begin_request`
handler to let user handle the request. In the handler, user code
#include "mongoose.h"
int main(void) {
struct mg_server *server = mg_create_server(NULL);
mg_set_option(server, "document_root", ".");
mg_set_option(server, "listening_port", "8080");
for (;;) mg_poll_server(server, 1000); // Infinite loop, Ctrl-C to stop
mg_destroy_server(&server);
return 0;
}
To compile it, put
`mongoose.c`
,
`mongoose.h`
and
`minimal.c`
into one
folder, then run the following UNIX command:
cc minimal.c mongoose.c -o my_program
If you're on Windows, run this in a Visual Studio shell:
cl minimal.c mongoose.c /TC /MD
Mongoose can call user-defined functions when certain URIs are requested.
These functions are _called uri handlers_.
`mg_add_uri_handler()`
registers
an URI handler, and there is no restriction on the number of URI handlers.
Also, mongoose can call a user-defined function when it is about to send
HTTP error back to client. HTTP error handler function can be registered
with
`mg_set_http_error_handler()`
.
In a handler function, user code
can get all information about the request -- parsed headers, etcetera.
can get all information about the request -- parsed headers, etcetera.
Here is a list of well-commented embedding examples:
Here is a list of well-commented embedding examples:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment