unisonweb / http Goto Github PK
View Code? Open in Web Editor NEWUnison HTTP Library
Unison HTTP Library
Just turning structural type RequestHandler = RequestHandler (SimpleHttpRequest ->{IO, Exception} SimpleHttpResponse)
into
structural type RequestHandler g = RequestHandler (SimpleHttpRequest ->{g, IO, Exception} SimpleHttpResponse)
so that the handler can include other abilities.
Then you can write a program that will count visits to each URL. The following stores the number of visits to each URL.
serveWeb : '{IO, Exception} ()
serveWeb _ =
run =
host = HostName "127.0.0.1"
port = ServiceName "5560"
requestHandler = RequestHandler storeTrial
server host port requestHandler
unsafeRun! ('handle (Store.withInitialValue (Map.empty) run) with Log.default "Example Http Server")
storeTrial : SimpleHttpRequest -> {IO, base.Exception, Store (Map Text Nat)} SimpleHttpResponse
storeTrial req =
(RequestURI (Path p) oqs ourif) = requestURI req
Store.modify (incMap p)
okText ("hello " Text.++ p ++ " " ++ Nat.toText ((Map.getOrElse 0 p) Store.get))
incMap : a -> Map a Nat -> Map a Nat
incMap i m = Map.insert i ((Map.getOrElse 0 i m) + 1) m
Output of the PR command:
The changes summarized below are available for you to review, using the following command:
pull-request.load https://github.com/unisonweb/share:.unison.http https://github.com/luketollefson/allmyunisoncode:.prs._genericRequestHandler
Updates:
structural type RequestHandler
↓
structural type RequestHandler g
docs.example : '{IO} ()
↓
docs.example : '{IO} ()
+ #av070q37il : Author
+ unisoncomputing2021 : License
README : Doc
↓
README : Doc
RequestHandler.RequestHandler : (SimpleHttpRequest ->{IO, Exception} SimpleHttpResponse)
-> http.RequestHandler
↓
RequestHandler.RequestHandler : (SimpleHttpRequest ->{g, IO, Exception} SimpleHttpResponse)
-> RequestHandler g
server : HostName -> ServiceName -> http.RequestHandler -> '{IO, Exception, Log Text} ()
↓
server : HostName -> ServiceName -> RequestHandler g -> '{g, IO, Exception, Log Text} ()
+ #av070q37il : Author
+ unisoncomputing2021 : License
server.loop : http.RequestHandler -> Socket ->{IO, Exception, Log Text} r
↓
server.loop : RequestHandler g -> Socket ->{g, IO, Exception, Log Text} r
server.sendReceive : http.RequestHandler -> Socket ->{IO, Exception, Log Text} ()
↓
server.sendReceive : RequestHandler g -> Socket ->{g, IO, Exception, Log Text} ()
server.start : http.RequestHandler -> Socket ->{IO, Exception, Log Text} ()
↓
server.start : RequestHandler g -> Socket ->{g, IO, Exception, Log Text} ()
There were 1 auto-propagated updates.
patch patch (added 9 updates,
deleted 9)
Added definitions:
metadata.authors.lukeTollefson.guid : GUID
metadata.authors.lukeTollefson : Author
metadata.copyrightHolders.lukeTollefson : CopyrightHolder
metadata.licenses.lukeTollefson2022 : License
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.