Skip to content

Commit

Permalink
Merge pull request #78 from JuliaWeb/tan/misc
Browse files Browse the repository at this point in the history
use Project.toml, update travis configuration, handle change to Base.is_id_start_char
  • Loading branch information
tanmaykm authored Dec 23, 2019
2 parents 2787bfb + 4e20136 commit f7494a7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 24 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ os:
- linux
julia:
- 1.0
- 1.1
- 1.2
- 1.3
- nightly
matrix:
fast_finish: true
allow_failures:
- julia: nightly
notifications:
email: false
#script:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'Pkg.clone(pwd()); Pkg.build("ZMQ"); Pkg.build("JuliaWebAPI"); Pkg.test("JuliaWebAPI"; coverage=true)';
after_success:
- julia -e 'cd(Pkg.dir("JuliaWebAPI")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())';
# - julia -e 'cd(Pkg.dir("JuliaWebAPI")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())';
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())';
30 changes: 30 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name = "JuliaWebAPI"
uuid = "480116ec-64ea-5dec-baca-db6b11e96e37"
keywords = ["julia", "rest", "api"]
license = "MIT"
desc = "Julia package for deploying APIs"
version = "0.6.1"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
ZMQ = "c2297ded-f4af-51ae-bb23-16f91089e4e1"

[compat]
HTTP = "≥ 0.8.0"
ZMQ = "≥ 0.3.3"
julia = "1"

[extras]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Base64", "Test", "Random", "Sockets", "Logging", "Distributed"]
4 changes: 0 additions & 4 deletions REQUIRE

This file was deleted.

11 changes: 2 additions & 9 deletions src/APIResponder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function call_api(api::APISpec, conn::APIResponder, args, data::Dict{Symbol,Any}
result = dynamic_invoke(conn, api.fn, args...; data...)
respond(conn, api, :success, result)
catch ex
logerr("api_exception: ", ex)
@error("api_exception", exception=(ex, backtrace()))
respond(conn, api, :api_exception, string(ex))
end
end
Expand Down Expand Up @@ -163,7 +163,7 @@ function process(conn::APIResponder; async::Bool=false)
try
call_api(conn.endpoints[command], conn, args(conn.format, msg), data(conn.format, msg))
catch ex
logerr("exception ", ex)
@error("exception in process", exception=(ex, backtrace()))
respond(conn, conn.endpoints[command], :invalid_data)
end
end
Expand All @@ -190,10 +190,3 @@ function create_responder(apispecs::Array, addr, bind, nid, open=false)
end
api
end

function logerr(msg, ex)
iob = IOBuffer()
write(iob, msg)
showerror(iob, ex)
@error(String(take!(iob)))
end
5 changes: 2 additions & 3 deletions src/http_rpc_server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end

function isvalidcmd(cmd)
isempty(cmd) && return false
Base.is_id_start_char(cmd[1]) || return false
((cmd[1] == ':') || Base.is_id_start_char(cmd[1])) || return false
for c in cmd
Base.is_id_char(c) || return false
end
Expand Down Expand Up @@ -198,8 +198,7 @@ function http_handler(apis::Channel{APIInvoker{T,F}}, preproc::Function, req::HT
end
catch e
res = HTTP.Response(500)
Base.showerror(stderr, e, catch_backtrace())
@error("Exception in handler: ", e)
@error("Exception in handler: ", exception=(e, backtrace()))
end
@debug("response", res)
return res
Expand Down
15 changes: 12 additions & 3 deletions test/clnt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ function run_clnt(fmt, tport)
@test resp["code"] == 500
@test occursin("testing exception handling", resp["data"]["data"])

# Test terminate
println("testing server termination...")
resp = apicall(apiclnt, ":terminate")
@test resp["code"] == 200
@test isempty(resp["data"])

close(ctx)
close(tport)
end
Expand All @@ -92,19 +98,22 @@ function run_httpclnt()
resp = HTTP.get("http://localhost:8888/invalidapi"; status_exception=false)
@test resp.status == 404

resp = JSON.parse(String(HTTP.get("http://localhost:8888/testfn1/1/2"; status_exception=false).body))
respstr = String(HTTP.get("http://localhost:8888/testfn1/1/2"; status_exception=false).body)
resp = JSON.parse(respstr)
@test resp["code"] == 0
@test resp["data"] == 5

resp = JSON.parse(String(HTTP.get("http://localhost:8888/testfn1/1/2"; query=Dict(:narg1=>3,:narg2=>4), status_exception=false).body))
respstr = String(HTTP.get("http://localhost:8888/testfn1/1/2"; query=Dict(:narg1=>3,:narg2=>4), status_exception=false).body)
resp = JSON.parse(respstr)
@test resp["code"] == 0
@test resp["data"] == 11

println("testing file upload...")
filename = "a.txt"
postdata = """------WebKitFormBoundaryIabcPsAlNKQmowCx\r\nContent-Disposition: form-data; name="filedata"; filename="a.txt"\r\nContent-Type: text/plain\r\n\r\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\r\n------WebKitFormBoundaryIabcPsAlNKQmowCx\r\nContent-Disposition: form-data; name="filename"\r\n\r\na.txt\r\n------WebKitFormBoundaryIabcPsAlNKQmowCx--\r\n"""
headers = Dict("Content-Type"=>"multipart/form-data; boundary=----WebKitFormBoundaryIabcPsAlNKQmowCx")
resp = JSON.parse(String(HTTP.post("http://localhost:8888/testFile"; headers=headers, body=postdata, status_exception=false).body))
respstr = String(HTTP.post("http://localhost:8888/testFile"; headers=headers, body=postdata, status_exception=false).body)
resp = JSON.parse(respstr)
@test resp["code"] == 0
@test resp["data"] == "5,446"

Expand Down

2 comments on commit f7494a7

@tanmaykm
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/7077

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.1 -m "<description of version>" f7494a7139234367f5388495cc80163150b3d8da
git push origin v0.6.1

Please sign in to comment.