GithubHelp home page GithubHelp logo

isabella232 / httpsrv Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yeslogic/httpsrv

0.0 0.0 0.0 140 KB

License: BSD 2-Clause "Simplified" License

C 34.02% Mercury 65.92% Makefile 0.06%

httpsrv's Introduction

httpsrv

httpsrv is an embedded HTTP server for Mercury programs. It lets you write a Mercury program that exposes an HTTP interface fairly easily.

httpsrv works with both the low-level and high-level C backends, and should work on any platform supported by libuv (some small changes may be required).

Requirements

libuv and http-parser:

Documentation

The API begins in src/httpsrv.m. There is no documentation yet but hopefully you can figure it out from the sample application in sample/httpsrv_test.m.

The API is subject to change as needs arise.

httpsrv itself runs on a single thread since libuv implements a single threaded event loop. It is expected that users will spawn multiple native threads to handle requests so that handling of a single request will not block progress of the rest of the program. You will probably want to implement a thread pool of some sort.

Mercury green threads (i.e. thread.spawn in non-.par grades) are not supported because we can't multiplex execution of Mercury code with execution of httpsrv.

Building the sample application

On Linux, first install libuv and http-parser development libraries using your distribution's package manager.

Run make in the sample directory to produce the httpsrv_test program. Start the program, then go to http://localhost:8000 in a web browser to see the output. You can also visit URLs containing different paths or query parameters, e.g. http://localhost:8000/foo?bar=1

You can test the static file and multipart/form-data support as well. Here is a curl command to upload a file:

curl http://localhost:8000/upload -F upload=@FILENAME

Then to download the file:

curl http://localhost:8000/static/FILENAME

httpsrv's People

Contributors

mikeday avatar wangp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.