it's my first post on StackOverflow :)
We're writing RESTful API backend using Spring Data Rest. To add association we're using the request:
POST /favouriteFolders/7/posts HTTP/1.1
Host: localhost:8080
Content-Type: text/uri-list
http://localhost:8080/posts/68
http://localhost:8080/posts/418
Request format is described here:
http://docs.spring.io/spring-data/rest/docs/2.5.1.RELEASE/reference/html/#_post_2
Our iOS developer has problem sending this kind of request using RestKit
https://github.com/RestKit/RestKit
Any ideas how to use RestKit in this situation?
Or maybe we should use other REST client to handle this specific requests ?
Thanks in advance!
Related
I'm pretty new to submitting POST requests to API's using API credentials and am looking for an explanation on how it's done in Ruby on Rails.
I'm using the Shipwire API and am trying to POST to /orders.
POST /api/v3/orders HTTP/1.1
Host: api.beta.website.com
Authorization: Basic TG9vayBhdCB0aGF0OyBEdWNrcy4uLm9uIGEgbGFrZSEK
I have an Order object ready but am wondering if anyone could shed some light on this.
Httparty gem will help you make any kind of ReST api requests. You will find lots of tutorials on how to perform basic auth using this gem.
However, before jumping on code directly, i would suggest you to understand the request and response on the sandbox mode using the postman plugin for chrome.
I am making a POST call to get oAuth token in JMeter. So that I can upload files to Google Drive. Below is my request details in JMeter.
POST https://accounts.google.com/o/oauth2/token
POST data:
client_id=<my_client_id>&auth_uri=https%3A%2F%2Faccounts.google.com%2Fo%2Foauth2%2Fauth&token_uri=https%3A%2F%2Faccounts.google.com%2Fo%2Foauth2%2Ftoken&client_secret=<my_client_secret>&grant_type=authorization_code&redirect_uris=%5B%22urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob%22%2C+%22127.0.0.1%3A3000%22%5D%0A&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive
[no cookies]
Request Headers:
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 424
Host: accounts.google.com
User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_121)
But I am getting below error. Any help is appreciated. Thanks.
{
:
"error"
: : "invalid_request",
: "error_description" : "Missing required parameter: code"
}
I can not help you with JMeter but I can tell you what the error message means.
The grant_type=authorization_code is the second step in the Oauth2 flow. It has a few required parameters one of them is code.
https://accounts.google.com/o/oauth2/token
code=4/X9lG6uWd8-MMJPElWggHZRzyFKtp.QubAT_P-GEwePvB8fYmgkJzntDnaiAI&client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code
The code in question is the code that was returned from the initial request for the user to approve the applications access.
I would also like to add that Google has a number of official client libraries that will deal with these calls for you. Using one of those is much easer then trying to understand the Oauth2 flow if you don't need to. If you cant use the library and you are interested in seeing the full Oauth2 flow to google I have a tutorial on it Google 3 legged Oauth2 flow it shows the pure HTTP calls.
I would recommend using Google OAuth Java Client Library from JSR223 Test Elements using Groovy as a programming language, this is the fastest and the easiest way to obtain/refresh OAuth tokens.
See How to Run Performance Tests on OAuth Secured Apps with JMeter article for detailed explanation and an authorization example.
I have an iOS app that is working and able to connect to a RESTful PHP Webservice. The webservice was initially built in native PHP and now I am migrating it to a Symfony2 web service. On the iOS side, I am sending requests as JSON, the server processes the data and returns a JSON response data, everything works pretty well.
Now, my symfony2 webservice is able to respond with the correct response to requests made from the browser window or terminal using httpie (for testing) and it returns json data in the browswer window if I specify .json in the parameters. However, I am not sure how to make the iOS app send the request rather than the browser. I am using the FOSRestBundle if that information is of any significance. Here is an example from the terminal:
http http://serveripaddress/web/app_dev.php/users/1.json Accept:application/json
It returns json data representation of the user with the id = 1 as expected:
HTTP/1.1 200 OK
Allow: GET, PUT, DELETE
Cache-Control: no-cache
Content-Type: application/json
Date: Fri, 29 Nov 2013 20:15:43 GMT
Server: Apache/2.2.22 (Ubuntu)
Set-Cookie: PHPSESSID=n8o72oq61isruuov1bqgc9udf5; path=/
Transfer-Encoding: chunked
X-Debug-Token: 6c3818
X-Powered-By: PHP/5.3.10-1ubuntu3.8
{
"id": 1,
"last_name": "Robinson",
"first_name": "Jack",
....More data truncated ...
}
From my browser, I can get the same result by using: http://serveripaddress/web/app_dev.php/users/1.json in the address bar. How can I make the iOS app send the same request? I guess the only change I need is in the symfony2 code to accept the request? Kindly give a brief example and I can figure out the rest from the example.
Edited with more detail:
Just to clarify, what I need is how to initiate a connection to the server-side REST Symfony2 application. Again, this I have previously done when using native PHP but how do I connect to a Symfony2 route? While using the native version, what I did was to construct a dictionaryWithObjectandKeys passing key value pairs of the command (on the PHP side) and the arguments as JSON and having the server side return JSON data response and a success or failure, simple and straightforward. How can this be done if I am using Symfony2 which I guess the commands now become a route? I am using AFNetworking and everything on the iOS client side should not need changes except the part where I connect to Symfony2. Kindly give an example to give me a concrete picture.
You can use AFNetworking 2 for example. It is a complete framework that allows you to consume web services (and more).
By the way, you could simply use (and fire) NSURLRequest, but if your application interact a lot with a webService i recommend to use AFNetworking. (Trust me, it is really something that you want to know how to use if you want to make apps on iOS)
I think binding to session and cookies may violate REST nature. I strongly recommend you to use something like WSSE. You can use EscapeWSSEAuthenticationBundle for WSSE. Or create your own.
Also useful link to dive deep:
How to create a custom Authentication Provider
Configure WSSE on Symfony2 with FOSRestBundle
I have recently transferred my app over to stack mob, however I'm having difficulty with using the REST Api within my AFHTTP framework. Stackmob returns it's own version of the application/json response. It is actually returned as application/vnd.stackmob+json;
The AFHttp framework doesn't accept this, therefore I need a way of either asking stackmob to only return a standard application/json response, or tweak AFHTTP to accept this customer stackmob response.
Any help would be appreciated.
Hi I am trying to setup an api to allow a 3rd parties webhooks a destination to post application/x-www-form-urlencoded.
I have only ever worked with json and xml with the webapi.
Do I need to create a custom mediatype to accept this or should it work by default?
Any suggestions would be appreciated.
UPDATE
I took a look at the example provided however I am still not to sure an example of the data the webhook will send to my api looks like.
How am I meant to setup my controller to accept this?
POST /some-path HTTP/1.1
Host: your.host.example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 2837
Connection: keep-alive
Accept: /
environment=prod&domain_prefix=example&type=product.update&payload=%7B%22id%22%3A%229fe945bc-2d20-11e2-8057-080027706aa2%22%2C%22retailer_id%22%3A%229a5521c3-2d20-11e2-8057-080027706aa2%22%2C%22sku%22%3A%229416050901074%22%2C%22handle%22%3A%221000001%22%2C%22source%22%3A%22USER%22%2C%22active%22%3A%221%22%2C%22name%22%3A%22Ginger+Beer%22%2C%22description%22%3A%22%3Cp%3EA+delicious+ginger+beer+that+is+both+refreshing+and+good+value+for+money.%3C%5C%2Fp%3E%22%2C%22supplier%22%3A%7B%22id%22%3A%229fc84329-2d20-11e2-8057-080027706aa2%22%2C%22retailer_id%22%3A%229a5521c3-2d20-11e2-8057-080027706aa2%22%2C%22name%22%3A%22Brewer+Supplies+Ltd.%22%2C%22description%22%3A%22We+supply+all+things+brewed%5Cn%22%2C%22source%22%3A%22USER%22%7D%2C%22brand%22%3A%7B%22id%22%3A%229fb8e69d-2d20-11e2-8057-080027706aa2%22%2C%22name%22%3A%22Vaughan%27s+Ginger+Beer+Brewing+Company%22%7D%2C%22inventory%22%3A%5B%7B%22product_id%22%3A%229fe945bc-2d20-11e2-8057-080027706aa2%22%2C%22outlet_id%22%3A%229aee412b-2d20-11e2-8057-080027706aa2%22%2C%22attributed_cost%22%3A%221%22%2C%22count%22%3A%2222%22%2C%22reorder_point%22%3A%2212%22%2C%22restock_level%22%3A%2240%22%7D%2C%7B%22product_id%22%3A%229fe945bc-2d20-11e2-8057-080027706aa2%22%2C%22outlet_id%22%3A%229ae97219-2d20-11e2-8057-080027706aa2%22%2C%22attributed_cost%22%3A%221%22%2C%22count%22%3A%2214%22%2C%22reorder_point%22%3A%226%22%2C%22restock_level%22%3A%2220%22%7D%5D%2C%22price_book_entries%22%3A%5B%7B%22id%22%3A%22a1098b59-2d20-11e2-8057-080027706aa2%22%2C%22product_id%22%3A%229fe945bc-2d20-11e2-8057-080027706aa2%22%2C%22price%22%3A%222.00%22%2C%22tax%22%3A%220.25%22%2C%22type%22%3A%22BASE%22%2C%22customer_group_id%22%3A%229b097e69-2d20-11e2-8057-080027706aa2%22%2C%22customer_group_name%22%3A%22All+Customers%22%2C%22tax_id%22%3A%229a025ff0-2d20-11e2-8057-080027706aa2%22%2C%22tax_name%22%3A%22NZ+GST%22%2C%22tax_rate%22%3A%220.150000%22%7D%2C%7B%22id%22%3A%22a1318cf0-2d20-11e2-8057-080027706aa2%22%2C%22product_id%22%3A%229fe945bc-2d20-11e2-8057-080027706aa2%22%2C%22price%22%3A%221.90%22%2C%22tax%22%3A%220.24%22%2C%22type%22%3A%22GENERAL%22%2C%22customer_group_id%22%3A%229b097e69-2d20-11e2-8057-080027706aa2%22%2C%22customer_group_name%22%3A%22All+Customers%22%2C%22tax_id%22%3A%229a025ff0-2d20-11e2-8057-080027706aa2%22%2C%22tax_name%22%3A%22NZ+GST%22%2C%22tax_rate%22%3A%220.150000%22%7D%2C%7B%22id%22%3A%22a13a6320-2d20-11e2-8057-080027706aa2%22%2C%22product_id%22%3A%229fe945bc-2d20-11e2-8057-080027706aa2%22%2C%22min_units%22%3A%2210.00%22%2C%22price%22%3A%221.50%22%2C%22tax%22%3A%220.19%22%2C%22type%22%3A%22BASE%22%2C%22customer_group_id%22%3A%229b097e69-2d20-11e2-8057-080027706aa2%22%2C%22customer_group_name%22%3A%22All+Customers%22%2C%22tax_id%22%3A%229a025ff0-2d20-11e2-8057-080027706aa2%22%2C%22tax_name%22%3A%22NZ+GST%22%2C%22tax_rate%22%3A%220.150000%22%7D%5D%7D
Yes, it supports it out of the box.
Please, take a look on that sample: ASP.NET Web API: Sending Form-Url-Encoded Data