I have a C# project that
gets a request to do work
performs the work
returns to the api a json object containing the results of the request
This is working fine. As the work is done there is a log file that gets populated with various information (date being processed, errors encountered, etc.). I want to include a request type that would tell my program to return to the API the log file. Because I want this to be "just another request" I am trying to figure out how to include the file as part of the json body being returned. Is this possible? Is there a way to include a file (actual file - not just the contents of the file) in the json body?
I know how to return the file as it's own post - is there a way to return a json AND a file in the same post or am I looking at 2 separate post requests? One for the json body and a separate post that would send the file?
Related
I want to make a json file on the server, and then update this json file using flutter http method in my app. I will get user ID, and if the user ID is already present in json file on the server, I just update the content of that items in the json file for this user only. If the user does not exist I add a new block into my json file on the server.
To do this, I first created a json file on the server and passed its url to http.post or http.put, but my json file is still empty. This means I cannot write anything in my json file.
Why?
Could you please let me know how I can achieve this?
My boss told me to compare json response and automate it. For eg: Store the json response which are coming from server and store them in one file now make second file to call first file and compare each json response. If response is right then automatically it will check mark saying "all response are correct" and vice versa. But I don't know how to do it. Can anyone guide me ?
I need to create a route (or not only one) that will do the following:
Read some ids from a .txt file (tokenized by /n)
For each id I will make a GET request to an url (http://myexample.com/something/**id**)
Every request will bring me a JSON
JSON will be unmarshaled to XML
So, I need a JSON file for every id in my file.txt. If I have 10 ids, I will get 10 JSON files from that url. I made the component that take me JSONs from a folder and unmarshal them to XML. Also, I tokenized my file.txt.
The problem is I don't know how to get a JSON file per each id, more exactly, how can I dynamically transform my url?
My code is:
<camel:route id="getRequestForEachId">
<camel:from uri="file:src/main/resources/idList?noop=true" />
<camel:split>
<camel:tokenize token="\n" />
<camel:to uri="stream:out" />
<camel:recipientList>
<camel:simple>
http://myexample.com/something/${body}
</camel:simple>
</camel:recipientList>
<camel:to uri="file:src/main/resources/jsonMandatFromReq" />
<!--from this will take my json->xml component-->
</camel:split>
</camel:route>
And with this code I get a 405 error:
HTTP operation failed invoking http://google.com/something/3 with statusCode: 405
That 3 is from file.txt with ids. So the url is built somehow, but I end with exceptions.
I would love concrete help, not a url to dynamic url on the camel site. Thank you very much!
LE:
The below answer solved my main problem, but I'm having another one now.
The GET method won't stop from making requests.
I want to have just one request for each id, and for this I'll get a JSON file per each request or id.
But my route is making requests continuously. After the list with ids is ending, it begins again. So I end with many JSON files for one id, when I need just one JSON file per id.
I don't want to override the existing JSON file. I want to have just one GET request per each id.
How can I solve this?
I have an application which uploads a large file in the XML format and sometimes a zip file. Now I want to have that file transferred to other application via REST API. I am thinking to pass the binary data in to json response.
I have the following questions for my approach.
Is sending binary in json the best approach/practice to do it?
Will this be PUT scenario as receiver application doesn't know about new uploaded file?
If that makes it easier for the second service to consume it, I see no problem with it. You can send it on any format you want, as long as it's accepted and you're setting the Content-Type and Accept headers properly.
You use a PUT only when you're sending a complete replacement of the resource at the target URI. If you know the final URI for that and if a GET to the same URI right after the PUT will retrieve as response the same body you just submitted, it makes sense to use PUT, otherwise, use a POST.
I'm learning how to use a third party API called Wunderground and I don't know how to request, receive, and use their results which is in a Json format.
If you see their website a developer can sign up for free and receives an API KEY. You can then request weather data in the following URL format.. http://api.wunderground.com/api/KEY/FEATURE/[FEATUREā¦]/[SETTINGā¦]/q/QUERY.FORMAT
So I have tried it in my web browser by typing some parameters and I received a very long Json file with the correct information (I checked). Problem is I don't have the slightest idea of how to create a variable which can make this request, and even if I was able to do that I don't know where should I receive the file and how to get only the results I want (in this case current weather).
You have to use Titanium.Network.HTTPClient to make request.
For code examples related to Json parsing you can use:
Appcelerator: Using JSON to Build a Twitter Client
HTTPClient()