GithubHelp home page GithubHelp logo

idris-httpclient's Introduction

idris http client

This is a very limited httpclient implementation based on libcurl for idris. It is still littered with debug output and currently just supports a minimal subset of HTTP features. It is probably not threadsafe, is leaking memory, the API is far from stable and not documented etc.

Example

Below are some examples of the usage for some request kinds:

module Main

import HttpClient

Show Reply where
  show (MkReply statusCode header body) = concat $ intersperse "\n"
                                          ["\nstatusCode: " ,
                                            show statusCode ,
                                          "header:" ,
                                            show header,
                                          "body:",
                                            body]

example: String -> IO (Response Reply) -> IO ()
example intro resp= do
  putStrLn intro
  putStrLn $ show !resp
  putStrLn "\n\n\n"

main: IO ()
main = do
    example "GET request" $ httpClient
                          $ get
                          $ url "http://httpbin.org/get"

    example "POST request" $ httpClient
                           $ post "language=idris&http=libcurl" .
                             withHeader (Link, "up") .
                             withHeader (Accept, "*/*")
                           $ url "http://httpbin.org/post"

    example "DELETE request" $ httpClient $ delete "" .
                              withHeaders [
                                (User_Agent, "idris-httpclient"),
                                (X_ "Some-Header", "my-data")
                                ]
                            $ url "http://httpbin.org/delete"

    example "Follow request" $ httpClient $ get
                             $ follow
                             $ url "http://httpbin.org/redirect/1"

Compile this with

idris -p httpclient Main.idr -o main

Installation

Installation is only tested on Mac OS X. You will need libcurl (and idris 0.10.2):

brew install curl

You will also need the lightyear parser library available from LightYear. Follow the build instructions to put it into your Idris distribution.

The Makefile in /src assumes a standard location. If that is not ok, adopt to your needs. If you have the prerequisites, just do:

make install

You will see a warning about a missing main file - that is ok, as long everything typechecks.

Issues

This is pretty much a learning project for me. If you find this project useful, and would like to have features, I am happy to learn in areas which help you. If you have suggestions to make the code better - please let me know.

memstream

Memstream implementation taken from http://piumarta.com/software/memstream/

idris-httpclient's People

Contributors

justjoheinz avatar

Stargazers

Rahul Chhabra avatar Shane Delmore avatar Jacob Thomas Errington avatar Eduardo Pareja Tobes avatar Jan S avatar Eric Bailey avatar Rick Elrod avatar  avatar Alex Gryzlov avatar Alexander Carter avatar

Watchers

 avatar James Cloos avatar Jacob Thomas Errington avatar  avatar Andrey Vlasov avatar

Forkers

yurrriq machunter

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.