JuliaLang/julia — Issue #433: HTTP interface
Author: afriggeri
Created: 2012-02-21 15:01:32+00:00
State: open

Just wondering if some kind of network capability/interface was planned to be included in the core, or does something like this belongs to a library :

abstract Verb
abstract Get <: Verb
abstract Post <: Verb
abstract Put <: Verb
abstract Delete <: Verb

type Url
url::String
end

macro url_str(p)
Url(p)
end

# Catch all unknown HTTP verbs
function open{T<:Verb}(url::Url, ::Type{T})
error("Verb $(T) not implemented")
end

# Actual implementation for GET
function open(url::Url, ::Type{Get})
# here would go the implementation
return "Yada yada content"
end

# Assume GET if no method is specified
open(url::Url) = open(url, Get)

# Examples
print(open(url"http://www.julialang.org"))
print("\n\n")
print(open(url"http://www.julialang.org", Post))

Output :

Yada yada content

Verb Post not implemented
in error, /Users/adrien/Sources/julia/j/error.j:5
in open, http.j:17
in include, src/boot.j:192
in process_options, /Users/adrien/Sources/julia/j/client.j:163
in _start, /Users/adrien/Sources/julia/j/client.j:201
at http.j:32