digitalmars.D.learn - Web APis
- Axel Casillas (18/18) Dec 30 2023 Hi there,
- ryuukk_ (9/27) Dec 31 2023 Try this:
- ryuukk_ (1/1) Dec 31 2023 nvm, that's not what you are asking for
- Alexandru Ermicioi (9/27) Dec 31 2023 Perhaps:?
Hi there,
I'm trying to implement web api's into a terminal program. With 
some help at the IRC have gotten pretty far but just hit a 
roadblock trying to manipulate the web api to accept input from 
the user.
Example:
auto content = 
get("www.webapiurl.com/data/v4/example?name=category&from=2022-01-24&to=2023-01-24&apikey=01010101010101010101");
writefln! %s (content);
the above is just an example and for the most part it works but I 
am unable to make the 'category','from=date' and 'to=date' a user 
modified variable.
It doesn't matter how I attempt to split the API into different 
sections and define variables before running the program it wont 
compile.
Has anybody ever run into this and if someone has could you point 
me to some example code that might make it ease for me to 
understand, would greatly appreciate.
 Dec 30 2023
On Sunday, 31 December 2023 at 04:40:02 UTC, Axel Casillas wrote:
 Hi there,
 I'm trying to implement web api's into a terminal program. With 
 some help at the IRC have gotten pretty far but just hit a 
 roadblock trying to manipulate the web api to accept input from 
 the user.
 Example:
 auto content = 
 get("www.webapiurl.com/data/v4/example?name=category&from=2022-01-24&to=2023-01-24&apikey=01010101010101010101");
 writefln! %s (content);
 the above is just an example and for the most part it works but 
 I am unable to make the 'category','from=date' and 'to=date' a 
 user modified variable.
 It doesn't matter how I attempt to split the API into different 
 sections and define variables before running the program it 
 wont compile.
 Has anybody ever run into this and if someone has could you 
 point me to some example code that might make it ease for me to 
 understand, would greatly appreciate.
Try this:
```D
import std.uri;
auto content = 
get("www.webapiurl.com/data/v4/example?name=category&from=2022-01-24&to=2023-01-24&apikey=01010101010101010101".encode);
```
Notice the ``.encode``
https://dlang.org/phobos/std_uri.html#.encode
 Dec 31 2023
On Sunday, 31 December 2023 at 04:40:02 UTC, Axel Casillas wrote:
 Hi there,
 I'm trying to implement web api's into a terminal program. With 
 some help at the IRC have gotten pretty far but just hit a 
 roadblock trying to manipulate the web api to accept input from 
 the user.
 Example:
 auto content = 
 get("www.webapiurl.com/data/v4/example?name=category&from=2022-01-24&to=2023-01-24&apikey=01010101010101010101");
 writefln! %s (content);
 the above is just an example and for the most part it works but 
 I am unable to make the 'category','from=date' and 'to=date' a 
 user modified variable.
 It doesn't matter how I attempt to split the API into different 
 sections and define variables before running the program it 
 wont compile.
 Has anybody ever run into this and if someone has could you 
 point me to some example code that might make it ease for me to 
 understand, would greatly appreciate.
Perhaps:?
```d
auto content = 
get(format("www.webapiurl.com/data/v4/example?name=category&from=%s&to=%s&apikey=01
10101010101010101", fromDate, toDate));
writefln!"%s"(content);
```
Best regards,
Alexandru
 Dec 31 2023








 
  
  
 
 ryuukk_ <ryuukk.dev gmail.com>
 ryuukk_ <ryuukk.dev gmail.com> 