GithubHelp home page GithubHelp logo

http's People

Contributors

hojberg avatar rlmark avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

http's Issues

Make the `RequestHandler` type generic

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

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.