[Django]-How to send POST request using Julia lang HTTP library to a Django RESTFUL API (DRF)

2👍

Julia 1.7, 1.8

If you are sending json formatted data (simple Django POST request):

begin

using JSON
using HTTP

const url = "http://127.0.0.1:8000/api/profile"
payload = Dict("email" => "email@email.com", "password" => "12345password")

response = HTTP.request(
        "POST", url, ["Content-Type" => "application/json"], JSON.json(payload))

# this is necessary, JULIA discontinued python style Dictionaries
response = JSON.parse(String(response.body))
println(response)


end

If you are sending header information like Authentication tokens, etc.

begin

using JSON
using HTTP

const url = "http://127.0.0.1:8000/api/profile"
payload = Dict("email" => "email@email.com", "password" => "12345password")
access_token = "some access token"

headers = Dict(
        "Content-Type" => "application/json",
        "Authorization" => "Bearer $access_token")

response = HTTP.request(
        "POST", url, headers, JSON.json(payload))

# this is necessary, JULIA discontinued python style Dictionaries
response = JSON.parse(String(response.body))
println(response)


end
👤Koops

Leave a comment