All Projects → DarrenN → Simple Http

DarrenN / Simple Http

Licence: bsd-3-clause
Make simple HTTP requests with Racket

Programming Languages

racket
414 projects

Projects that are alternatives of or similar to Simple Http

Httpie
A Node.js HTTP client as easy as pie! 🥧
Stars: ✭ 563 (+2459.09%)
Mutual labels:  http-client
Gun
HTTP/1.1, HTTP/2 and Websocket client for Erlang/OTP.
Stars: ✭ 710 (+3127.27%)
Mutual labels:  http-client
Requests3
Requests 3.0, for Humans and Machines, alike. 🤖
Stars: ✭ 813 (+3595.45%)
Mutual labels:  http-client
Fast Android Networking
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀
Stars: ✭ 5,346 (+24200%)
Mutual labels:  http-client
Nba
Node.js client for nba.com API endpoints
Stars: ✭ 637 (+2795.45%)
Mutual labels:  http-client
Gout
gout to become the Swiss Army Knife of the http client @^^@---> gout 是http client领域的瑞士军刀,小巧,强大,犀利。具体用法可看文档,如使用迷惑或者API用得不爽都可提issues
Stars: ✭ 749 (+3304.55%)
Mutual labels:  http-client
Ocaml Cohttp
An OCaml library for HTTP clients and servers using Lwt or Async
Stars: ✭ 533 (+2322.73%)
Mutual labels:  http-client
Sylar
C++高性能分布式服务器框架,webserver,websocket server,自定义tcp_server(包含日志模块,配置模块,线程模块,协程模块,协程调度模块,io协程调度模块,hook模块,socket模块,bytearray序列化,http模块,TcpServer模块,Websocket模块,Https模块等, Smtp邮件模块, MySQL, SQLite3, ORM,Redis,Zookeeper)
Stars: ✭ 895 (+3968.18%)
Mutual labels:  http-client
Restclient
🦄 Simple HTTP and REST client for Unity based on Promises, also supports Callbacks! 🎮
Stars: ✭ 675 (+2968.18%)
Mutual labels:  http-client
Ky
🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
Stars: ✭ 7,047 (+31931.82%)
Mutual labels:  http-client
Urllib
Request HTTP(s) URLs in a complex world
Stars: ✭ 600 (+2627.27%)
Mutual labels:  http-client
Finch
Elixir HTTP Client focused on performance
Stars: ✭ 633 (+2777.27%)
Mutual labels:  http-client
Node Fetch
A light-weight module that brings the Fetch API to Node.js
Stars: ✭ 7,176 (+32518.18%)
Mutual labels:  http-client
Poco
The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
Stars: ✭ 5,762 (+26090.91%)
Mutual labels:  http-client
Uplink
A Declarative HTTP Client for Python
Stars: ✭ 824 (+3645.45%)
Mutual labels:  http-client
Http Client
Async HTTP/1.1+2 client for PHP based on Amp.
Stars: ✭ 553 (+2413.64%)
Mutual labels:  http-client
Skinny Framework
🚝 "Scala on Rails" - A full-stack web app framework for rapid development in Scala
Stars: ✭ 719 (+3168.18%)
Mutual labels:  http-client
Httpcache
Get a working HTTP Cache in Go (Golang) with only 3 lines of code!!!!
Stars: ✭ 17 (-22.73%)
Mutual labels:  http-client
Redux Axios Middleware
Redux middleware for fetching data with axios HTTP client
Stars: ✭ 902 (+4000%)
Mutual labels:  http-client
Parallec
Fast Parallel Async HTTP/SSH/TCP/UDP/Ping Client Java Library. Aggregate 100,000 APIs & send anywhere in 20 lines of code. Ping/HTTP Calls 8000 servers in 12 seconds. (Akka) www.parallec.io
Stars: ✭ 777 (+3431.82%)
Mutual labels:  http-client

simple-http Build Status Coverage Status

⚠️ You probably want to use http-easy instead.

Make simple HTTP requests with Racket

 (require simple-http) package: simple-http

Very small library for making HTTP requests. Attempts to handle the server response and convert into the correct data type based on Content-Type headers. Heavily inspired and influenced by racket-request.

The general use case for this is when you want to make repeated requests to an API. You can setup a requester with the relevant auth headers and base URL, then make requests using the available procedures, get, put, etc.

Responses are parsed into jsexpr?, xexpr?, or string? depending on which requester? is used.

Example JSON request and response:

; Setup a json-request using SSL and pointed at httpbin.org
(define httpbin-org                                        
  (update-headers                                          
    (update-ssl                                            
      (update-host json-requester "httpbin.org") #t)       
   '("Authorization: 8675309")))                           
                                                           
; Query params for the request                             
(define params '((foo . "12") (bar . "hello")))            
                                                           
; Make a GET to https://httpbin.org/get?foo=12&bar=hello   
(define response (get httpbin-org "/get" #:params params)) 

Example:

> response                                                        
(json-response                                                    
 "HTTP/1.1 200 OK"                                                
 '#hasheq((X-Powered-By . ("Flask"))                              
          (Access-Control-Allow-Credentials . ("true"))           
          (Connection . ("close"))                                
          (Content-Type . ("application/json"))                   
          (Via . ("1.1 vegur"))                                   
          (Date . ("Sun, 14 May 2017 00:34:47 GMT"))              
          (X-Processed-Time . ("0.000745058059692"))              
          (Access-Control-Allow-Origin . ("*"))                   
          (Server . ("meinheld/0.6.1"))                           
          (Content-Length . ("408")))                             
 '#hasheq((url . "https://httpbin.org/get?foo=12&bar=hello")      
          (headers                                                
           .                                                      
           #hasheq((Authorization . "8675309")                    
                   (Host . "httpbin.org")                         
                   (Connection . "close")                         
                   (Content-Type . "application/json")            
                   (Accept . "application/json")                  
                   (Accept-Encoding . "gzip")                     
                   (User-Agent . "Racket/6.8 (net/http-client)")))
          (origin . "255.255.255.255")                              
          (args . #hasheq((bar . "hello") (foo . "12")))))        

1. Requesters

Requests are made by creating requesters and using functions to update them with relevant data such as base url, use SSL, etc.

(struct requester (host headers ssl type)  
    #:extra-constructor-name make-requester
    #:transparent)                         
  host : string?                           
  headers : hash?                          
  ssl : boolean?                           
  type : symbol?                           

Stores information about the types of requests to make (headers). You usually don’t need to use this directly, pre-loaded requesters are provided for you.

html-requester
json-requester
text-requester
xml-requester 

Pre-made requesters for requesting specific formats. Requests made with these will send the appropriate Accept and Content-Type headers. Responses will also be parsed according to their request type.

(update-host requester host) -> requester?
  requester : requester?                  
  host : string?                          

Change the host string in a requester. Returns the updated requester.

(update-ssl requester ssl) -> requester?
  requester : requester?                
  ssl : boolean?                        

Change whether the requester should make SSL requests or not. When set to #t requests will be changed to https. Returns the updated requester.

(update-headers requester headers) -> requester?
  requester : requester?                        
  headers : (listof string?)                    

Merges headers into the existing headers in the requester and returns the requester. Any headers passed to the function will overwrite any existing headers in the requester? with the same header key.

(update-headers req '("Authorization: 8675309" "x-foo: oof"))

2. Making requests

Requests are made using requesters to determine how data should be sent and received. Responses are returned as structs with their data encoded based on the requester used. If the server returns an error code a exn:fail:network:http:error? will be raised. If the data returned from the server is in a different format than requested or cannot be properly parsed then a exn:fail:network:http:read? will be raised.

(get requester uri [#:params params])                                
 -> (or/c html-response? json-response? text-response? xml-response?)
  requester : requester?                                             
  uri : string?                                                      
  params : (listof pair?) = '()                                      

Makes a GET request using the provided requester. #:params will be combined onto the URL as query parameters. Responses are structs.

(get                                            
 (update-host json-requester "httpbin.org")     
 "/get" #:params '((foo . "12") (bar . "quux")))
(post  requester                                                     
       uri                                                           
      [#:data data                                                   
       #:params params])                                             
 -> (or/c html-response? json-response? text-response? xml-response?)
  requester : requester?                                             
  uri : string?                                                      
  data : any/c = #f                                                  
  params : (listof pair?) = '()                                      

Makes a POST request using the provided requester. #:params will be combined onto the URL as query parameters. #:data is sent to the server in the body of the request. Responses are structs.

(post                                                        
 (update-host json-requester "httpbin.org")                  
 "/post"                                                     
 #:data (jsexpr->string (hasheq 'colossal-squid "drumbones"))
 #:params '((sort . "asc") (filter . "hits")))               
(put  requester                                                      
      uri                                                            
     [#:data data                                                    
      #:params params])                                              
 -> (or/c html-response? json-response? text-response? xml-response?)
  requester : requester?                                             
  uri : string?                                                      
  data : any/c = #f                                                  
  params : (listof pair?) = '()                                      

Makes a PUT request using the provided requester. #:params will be combined onto the URL as query parameters. #:data is sent to the server in the body of the request. Responses are structs.

(put                                                         
 (update-host json-requester "httpbin.org")                  
 "/put"                                                      
 #:data (jsexpr->string (hasheq 'white-zombie "thunderkiss"))
 #:params '((sort . "asc")))                                 
(patch  requester                                                    
        uri                                                          
       [#:data data                                                  
        #:params params])                                            
 -> (or/c html-response? json-response? text-response? xml-response?)
  requester : requester?                                             
  uri : string?                                                      
  data : any/c = #f                                                  
  params : (listof pair?) = '()                                      

Makes a PATCH request using the provided requester. #:params will be combined onto the URL as query parameters. #:data is sent to the server in the body of the request. Responses are structs.

(patch                                                       
 (update-host json-requester "httpbin.org")                  
 "/patch"                                                    
 #:data (jsexpr->string (hasheq 'white-zombie "thunderkiss"))
 #:params '((sort . "asc")))                                 
(delete requester uri [#:params params])                             
 -> (or/c html-response? json-response? text-response? xml-response?)
  requester : requester?                                             
  uri : string?                                                      
  params : (listof pair?) = '()                                      

Makes a DELETE request using the provided requester. #:params will be combined onto the URL as query parameters. Responses are structs.

(delete                                    
 (update-host json-requester "httpbin.org")
 "/delete"                                 
 #:params '((sort . "asc")))               

3. Responses

(struct html-response (status headers body)    
    #:extra-constructor-name make-html-response
    #:transparent)                             
  status : string?                             
  headers : hash?                              
  body : xexpr?                                
(struct json-response (status headers body)    
    #:extra-constructor-name make-json-response
    #:transparent)                             
  status : string?                             
  headers : hash?                              
  body : jsexpr?                               
(struct text-response (status headers body)    
    #:extra-constructor-name make-text-response
    #:transparent)                             
  status : string?                             
  headers : hash?                              
  body : string?                               
(struct xml-response (status headers body)     
    #:extra-constructor-name make-xml-response 
    #:transparent)                             
  status : string?                             
  headers : hash?                              
  body : xexpr?                                

Response bodies are decoded into a form determined by the requester used to make requests. If the response comes back in a form that can’t be processed or throws an error duing processing then a exn:fail:network:http:read? exception will be raised.

status is a string? such as "HTTP/1.1 200 OK". headers are a key value representation of the response headers:

#hasheq((Host . "httpbin.org")             
        (Connection . "close")             
        (Content-Type . "application/json")
        (Accept . "application/json"))     

4. Exceptions

(struct exn:fail:network:http:read (message                 
                                    continuation-marks      
                                    type)                   
    #:extra-constructor-name make-exn:fail:network:http:read
    #:transparent)                                          
  message : string?                                         
  continuation-marks : continuation-mark-set?               
  type : symbol?                                            

Raised when a response is either the wrong format (ex: HTML returned for a JSON request) or malformed and cannot be parsed by the relevant reader. type is a symbol to let you know which requester made the request, such as 'json, etc.

(struct exn:fail:network:http:error (message                 
                                     continuation-marks      
                                     code                    
                                     type)                   
    #:extra-constructor-name make-exn:fail:network:http:error
    #:transparent)                                           
  message : string?                                          
  continuation-marks : continuation-mark-set?                
  code : number?                                             
  type : symbol?                                             

Raised when the server responds with an error code. code is the numeric error code returned by the server. type is a symbol? letting you know which requester made the request (ex: 'json).


Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].