daveaztig14

daveaztig14

How to use curl as input in elixir script?

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.

Most Liked

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

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.

Where Next?

Popular in Questions Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New

We're in Beta

About us Mission Statement