{ title: 'Embedding GoAhead', crumbs: [ { "Developer's Guide": 'index.html' }, ], }

# Embedding GoAhead

When embedding GoAhead in your application or system, you have two alternatives:

1. Use the existing GoAhead main program and extend GoAhead via Javascript and goforms.
2. Link the GoAhead library with a custom main program.

## The GoAhead Program

The GoAhead product includes a fully-featured HTTP server program called goahead that uses the GoAhead HTTP library. You can also modify the goahead.c main program to customize according to your specific requirements. line of code.

## Embed the GoAhead Library

You can link the GoAhead library with your application to enable it to listen for HTTP requests and thus become a HTTP server itself. Embedding the GoAhead library is easy and can be done with as little as one line of code.

### Linking with the GoAhead Library

To include the GoAhead library in your program you need to do the following things:

1. Add #include "goahead.h" in your source files.
2. Add the GoAhead library to your Makefiles or Windows project files. This will mean adding libgo.lib on Windows or libgo.a on Unix.
3. Use one of the embedding APIs to create the HTTP server.

### Full Control API

The GoAhead library also provides an extensive API so you can precisely control how the web server is created and configured.

This example creates a web server using the "server.conf" configuration file and will service events until terminated.

    #include "goahead.h"
    int main(int argc, char **argv)
    {
        if (websOpen("web", "route.txt") < 0) {
            error("Can't open the web server runtime");
            return 0;
        }
        if (websListen(":80") < 0) {
            mprError("Can't listen on port 80");
            return 0;
        }
        websServiceEvents(NULL);
        websClose();
        return 0;
    }

## Extending via Javascript

The GoAhead Javascript web framework allows customization by direct embedding of Javascript code in HTML web pages. This code runs on the server-side before rendering the page to the client.

### API Details

For more details about the embedding API, please consult the GoAhead API.