http://snapframework.com/docs/tutorials/snap-api
main :: IO () main = quickHttpServe site
site :: Snap () site = ifTop (writeBS "hello world") <|> route [ ("foo", writeBS "bar") , ("echo/:echoparam", echoHandler) ] <|> dir "static" (serveDirectory ".")
echoHandler :: Snap () echoHandler = do param <- getParam "echoparam" maybe (writeBS "must specify echo/param in URL") writeBS param
-----
Rust (with third party library)
https://github.com/chris-morgan/rust-http/blob/master/src/ex...
//! A very simple HTTP server which responds with the plain text "Hello, World!" to every request.
#![crate_id = "hello_world"]
extern crate time; extern crate http;
use std::io::net::ip::{SocketAddr, Ipv4Addr}; use std::io::Writer;
use http::server::{Config, Server, Request, ResponseWriter}; use http::headers::content_type::MediaType;
#[deriving(Clone)] struct HelloWorldServer;
impl Server for HelloWorldServer { fn get_config(&self) -> Config { Config { bind_address: SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 8001 } } }
fn handle_request(&self, _r: Request, w: &mut ResponseWriter) { w.headers.date = Some(time::now_utc()); w.headers.content_length = Some(14); w.headers.content_type = Some(MediaType { type_: String::from_str("text"), subtype: String::from_str("plain"), parameters: vec!((String::from_str("charset"), String::from_str("UTF-8"))) }); w.headers.server = Some(String::from_str("Example")); w.write(b"Hello, World!\n").unwrap(); }
fn main() { HelloWorldServer.serve_forever(); }
Go (native)
package main
import ( "fmt" "net/http" )
func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) }
func main() { http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) }
Yeah, ok.
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, '127.0.0.1');
Haskell (with third party library)
main :: IO () main = quickHttpServe site site :: Snap () site = ifTop (writeBS "hello world") <|> route [ ("foo", writeBS "bar") , ("echo/:echoparam", echoHandler) ] <|> dir "static" (serveDirectory ".") echoHandler :: Snap () echoHandler = do param <- getParam "echoparam" maybe (writeBS "must specify echo/param in URL") writeBS param
//! A very simple HTTP server which responds with the plain text "Hello, World!" to every request. #![crate_id = "hello_world"] extern crate time; extern crate http; use std::io::net::ip::{SocketAddr, Ipv4Addr}; use std::io::Writer; use http::server::{Config, Server, Request, ResponseWriter}; use http::headers::content_type::MediaType; #[deriving(Clone)] struct HelloWorldServer; impl Server for HelloWorldServer { fn get_config(&self) -> Config { Config { bind_address: SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 8001 } } } fn handle_request(&self, _r: Request, w: &mut ResponseWriter) { w.headers.date = Some(time::now_utc()); w.headers.content_length = Some(14); w.headers.content_type = Some(MediaType { type_: String::from_str("text"), subtype: String::from_str("plain"), parameters: vec!((String::from_str("charset"), String::from_str("UTF-8"))) }); w.headers.server = Some(String::from_str("Example")); w.write(b"Hello, World!\n").unwrap(); } } fn main() { HelloWorldServer.serve_forever(); }
package main import ( "fmt" "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) } func main() { http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) }
like this
http://snapframework.com/docs/tutorials/snap-api
main :: IO () main = quickHttpServe site
site :: Snap () site = ifTop (writeBS "hello world") <|> route [ ("foo", writeBS "bar") , ("echo/:echoparam", echoHandler) ] <|> dir "static" (serveDirectory ".")
echoHandler :: Snap () echoHandler = do param <- getParam "echoparam" maybe (writeBS "must specify echo/param in URL") writeBS param
-----
Rust (with third party library)
https://github.com/chris-morgan/rust-http/blob/master/src/ex...
//! A very simple HTTP server which responds with the plain text "Hello, World!" to every request.
#![crate_id = "hello_world"]
extern crate time; extern crate http;
use std::io::net::ip::{SocketAddr, Ipv4Addr}; use std::io::Writer;
use http::server::{Config, Server, Request, ResponseWriter}; use http::headers::content_type::MediaType;
#[deriving(Clone)] struct HelloWorldServer;
impl Server for HelloWorldServer { fn get_config(&self) -> Config { Config { bind_address: SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 8001 } } }
}fn main() { HelloWorldServer.serve_forever(); }
-----
Go (native)
package main
import ( "fmt" "net/http" )
func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) }
func main() { http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) }
-----
Yeah, ok.