daveaztig14

daveaztig14

Hi,

I am totally new in phoenix, elixir, and ecto. I have been studying for a week about basics and all, so far I’m quite amazed and confused at the same time. Anyway, my problem is this, I have a curl request which is:

curl https://sample.com/environment
-H ‘Content-Type: application/json; charset=utf-8’
-d ‘{“ticket”: 1, “ver”: “0.0.1.0_env”, “os”: “android”}’

I want to use the values of the variables “ticket”, “ver” and “os” as an input in my elixir/ecto script which will query in a remote database. (values is changing each request)

I’m sorry for my question if its a little confusing. Please feel free to ask questions so that I can clarify things. And also I want to know it it truly possible.

Any suggestions, help, links and ideas are welcome. I want to eagerly learn this. Thank you.

First 4 of 4 Posts Switch mode

idi527

idi527

:waving_hand:

How do you plan to use curl from within the elixir app? If it’s

System.cmd("curl", ~w[
  https://sample.com/environment
  -H 'Content-Type: application/json; charset=utf-8'
  -d '{"ticket": #{ticket}, "ver": "#{version}", "os": "#{os}"}'
])

then you can #{interpolate} your variables like this.

However, I’d suggest looking into http clients in elixir/erlang, like :httpoison to make http requests instead of curl.

HTTPoison.get("https://sample.com/environment?ticket=#{ticket}&ver=#{version}&os=#{os}")
Qqwy

Qqwy

TypeCheck Core Team

While it is possible to use curl from Elixir directly, it seems like what you actually want to do, is to perform a remote HTTP request and read the results.
Instead of manually using curl, I suggest using a HTTP client library such as HTTPoison, which does much of the request/response parsing and error handling for you.

NobbZ

NobbZ

And now, here I am, understanding it completely different than @idi527 and @Qqwy did…

For me, it seems as if you want to a webserver that actually receives the curl request.

In this case, take a look at phoenix and/or plug.

daveaztig14

daveaztig14 OP

Hi @Qqwy @NobbZ @idiot,

I am so sorry for my late response. Just an update:

Based on the research I’ve made and the ideas and suggestions you’ve given me, I now have a simple elixir app where in it accepts a request like:

curl “http://localhost:8085/pass” -H Content-Type: application/json; charset=utf-8’ -d ‘{“ticket”: 1, “ver”: “1”, “os”: “1”}’

and the output is:

ticket: 1, ver: 0.0.1.0_develop, os: ios

SQL Query = select * from database where ticket= 1 AND ver= 1 AND os= 1

Thank you for all your help, ideas and suggestions. together with this link https://www.jungledisk.com/blog/2018/03/19/tutorial-a-simple-http-server-in-elixir/.

It really helped me alot.

My next step now is to connect to a database and query the statement using elixir/ecto. However, it is another topic.

Once again. Thank you.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement