HttpClient DELETE with object - dotnet-httpclient

I am making a solution against a REST-interface using C# - HttpClient and Newtonsoft.Json.
One of the methods requires a DELETE with URL and a JSON-object.
I am not able to change the REST-service, so it has to be solved in my own code.
What I am missing is the DELETE-alternative to myClient.PostAsJsonAsync(Url,json-object)
I am aware, that it seems to be possible using could be solved using HttpWebRequest, but I would rather continue using HttpClient.
So does someone have a clue about how to solve this?

Simply use HttpClient.DeleteAsync(url), and why not put the target of delete into the url, like this /api/products/id instead of passing a json object.

Related

How to fix "not key value coding-compliant" exception when using RestKit

I'm building an app that talks to an existing REST API. That API was built using a framework called Jackson, I believe, and I thought that I might use RestKit to handle the object creation of objects used by the API. However, I've run into a problem, Jackson likes to send and get JSON that contains structures like this: {"#id": 1, "id": 4} but RestKit chokes on "#id" with a "not key value coding-compliant for the key" exception.
Changing the existing API is going to be an uphill struggle, but I'm wondering if I can shim some sort of conversion that replaces "#id" with a legal key, like "AT__id" on incoming JSON and does the opposite conversion on outgoing JSON. My problem is that I'm new to RestKit and don't know where to begin. I'm contemplating tracing code to see where I might modify the code, but is anyone familiar enough with how it is structured to offer suggestions for where to begin and save me the effort?
I discovered that "#id" is a Jackson convention, not a requirement. We tested by changing it to something that conforms to the lowercase/ascii rule and it worked out perfectly. We'll change it for the next server update. This doesn't answer the question, but does solve the immediate problem.

Grails Override reserved work in a controller?

I am currently working on a Grails solution and I am looking to pass a URL using WSLite, I basically want to pass a bunch of query params and have them fired off. One of the params I need to have is session.name, I need this exactly like this as a 3rd party system can only read data as "session.WHATEVER". However when i enter the data below it has a problem with the "session." as it appears that session is a reserved word in grails. Is there anyway I can get grails not to pick-up the reserved word and just use session.name? Maybe by some sort of override?
def response = client.get(path:'/TestingService', query:[code:testCode, session.name: name])
Thanks
Use quotes:
query:[code:testCode, 'session.name': name]

Get request URI in jinja2?

I'm working on a Pylons project using Jinja2 templating. I want to test for the request URI and/or controller inside the Jinja2 templates - is there an equivalent to a getRequestUri() call? I can set a context variable as a flag inside all the controller methods to do what I want, but that seems a bit like writing my home address on each and every one of my house keys... i.e. not quite the right way to do it.
Solution: not quite a function call, but I can test against url.environ.PATH_INFO. It only gives me the URL path, not the hostname, and I don't know that it would give me the query string, but it gives me what I need.

How do you pass data between models in Ruby on Rails

I have a controller and I current have it using redirect going to another controller, I know I can pass data around using the :query...
Is there any way I can do this without the use of http as I'm finding it impossible to send a hash using http.
I cant find this information any where, what is the most common way of sharing data (slash sending) data from one controller to another?
please help been working on this for hours, btw am new to RoR
If you are redirecting the browser, you will have to use the query option as redirect actually tells the browser to make another request to a different path.
If you just want to render the other controllers action you could call:
render :template=>"path to view you want to render"
As for actually calling the other action? You could distill (refactor) the logic into a lib and call the same logic from both controllers, then use the same view for both..
I found my answer, I may have not been specific enough with the question. But you can pass a hash using the query string; which obviously (now that I think of it) converts it to a string duh. so I just use eval in the receiving hash,
eval(#params['inputData'] which gives me the hash.

How to access AJAX hash values in ASP.NET MVC?

I'm considering using the hash method to create static urls to content that is managed by ajax calls in a Asp.Net MVC. The proof of concept i'm working on is a profile page /user/profile where one can browse and edit different sections. You could always ask for the following url /user/profile#password to access directly to you profile page, in the change password section
However, i'm wondering if i'm not starting this the bad way, since apparently i can't access the part after the hash in any way, except by declaring a route value for the hash in global.asax. So i'm wondering if this is the right way to access this part of the url?
Am i supposed to declare a route value, or is there another way to work with hash values (a framework, javascript or mvc)?
Edited to add:
In pure javascript, i have no problem using the window.location.hash property, i'm not sure though how standard it is in today's browsers, hence the question about a javascript framework/plugin that would use it.
The thing is that the part that follows the hash (#) is never sent to the server into the HTTP request so the server has absolutely no way of reading it. So no need to waste time in searching for something that doesn't exist.
You could on the other hand tune your routes to generate links that contain the hash part so that client scripts can read it.
Send the hash value document.location.hash as a parameter to the controller action of your choice.
This can be done in the code if needed...
RedirectResult(Url.Action("profile") + "#password");
should work fine

Resources