Giter VIP home page Giter VIP logo

Comments (4)

rssdev10 avatar rssdev10 commented on June 29, 2024 2

Implementation of JSON request processing with Mux:

using Mux
using JSON

@app test = (
  Mux.defaults,
  page(respond("<h1>Hello World!</h1>")),

  page("/user/:user", req -> "<h1>Hello, $(req[:params][:user])!</h1>"),

  route("/resource/process", req -> begin
    obj = JSON.parse(String(req[:data]))

    @show obj

    Dict(:body => String(JSON.json(obj)),
         :headers => Dict("Content-Type" => "application/json")
         )
  end),

  Mux.notfound())

serve(test, 8080)

Base.JLOptions().isinteractive == 0 && wait()

Implementation of JSON request processing with Bukdu:

using Bukdu
using JSON

struct WelcomeController <: ApplicationController
    conn::Conn
end

function index(c::WelcomeController)
    render(JSON, "Hello World")
end

function process_resource(c::WelcomeController)
    json = JSON.parse(String(c.conn.request.body))

    @show json

    render(JSON, json)
end

routes() do
    get("/", WelcomeController, index)
    post("/resource/process", WelcomeController, process_resource)
end

Bukdu.start(8080)

Base.JLOptions().isinteractive == 0 && wait()

from juliawebapi.jl.

tanmaykm avatar tanmaykm commented on June 29, 2024

The primary purpose of this package is to enable exposing Julia functions as web APIs. Right now, the path elements are mapped to function parameters and query/form name-value pairs are mapped on to keyword args.

I unsure how requests with JSON body should fit to this paradigm.
Mux does seem to be a good alternative for this.

from juliawebapi.jl.

rssdev10 avatar rssdev10 commented on June 29, 2024

Actually Web APIs primary means usage of some exchange format like JSON or XML. Just as example - https://market.mashape.com/ or open API initiative https://www.openapis.org/ But in both cases it requires usage of POST request with some HTTP body content.

In general it is not so big issue to add support of multipart HTTP content at least for JSON. But primary it is depends on how are you positioning the library.

from juliawebapi.jl.

rssdev10 avatar rssdev10 commented on June 29, 2024

from juliawebapi.jl.

Related Issues (20)

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.