Newbie question: I have to rebuilt an old REST API, with some clients in Swagger 2.0. Unfortunatly some of the API calls use for HTTP post the following way: For the content it uses the POST body, but for a "sitekey" it use an URL Parameter.
so each post looks something like that:
POST api/update?sitekey=xxx HTTP/1.1
....
{"json": "content"}
I must not ignore the sitekey, so how would i model such a thing in swagger?
If you are using Jax-rs, you can use swagger's #ApiParam annotation. Depending on the jax-rs annotation (#QueryParam, #PathParam, etc.) used along with this annotation, swagger will identify the parameter placement correctly. See here: https://github.com/swagger-api/swagger-core/wiki/Annotations#apiparam
Related
I am writing a REST API, which supports POST/GET/DELETE method for the same url.
For the DELETE method, the API needs extra parameters (details of the deletion). But the library I am using doesn't support request body for DELETE method, how can I do it?
If I put the parameter in URL like:
DELETE /API/Resource/id/parameter
Then I break the RESTyness.
Or I need to use another method POST/PUT, which is not RESTy, either.
Why is POST / PUT not RESTy? Take a look at the twitter REST API: You can destroy a status by POSTing to /statuses/id/destroy. That request does accept parameters. You could do something similar to this:
POST /API/Resource/id/destroy
I think that is RESTy enough.
I'm trying to use the QBO v3 API object update function described here. The API explorer shows a different uri.
I'm trying to update an account with Id 42. Both of the following URIs get me a 401:
As the documentation would suggest:
https://quickbooks.api.intuit.com/v3/company/0123456789/account?requestid=42
(the above at least gives me a json blob with the 401)
As the api explorer would suggest:
https://qb.sbfinance.intuit.com/v3/company/0123456789/account?operation=update
(here I don't even get the json, just a plain 401)
My request body is successful when I use the api explorer, so I don't believe that's the problem. I also don't believe authentication is the problem, because I can successfully create objects and also make queries with the same headers.
What might I be missing?
Don't put the Account object's ID into the URL. The [?requestid=] from the documentation you mentioned apparently refers to an id related to the request (not the object in question). The API Explorer's URI appears to simply mislead (although I could certainly be missing something here).
In your example, just use this:
https://quickbooks.api.intuit.com/v3/company/0123456789/account
Let the headers and request body do the rest.
Correct BASE URI: https://quickbooks.api.intuit.com/v3/company/
you can refer example request/response section of any entity doc.
Ref -https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference/bill
To debug(401 authentication issue), you can use any standard RestClient.
In the following thread, I've explained how to use RestClinet plugin of Mozilla to test any QBO V3 endpoint.
InvalidTokenException: Unauthorized-401
You can download IPP's devkit and using that devkit you can call any endpoints easily.
https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits
Hope it will be useful.
Thanks
I'm implementing access to OAuth service in Play 2.0 application. Generally I'm doing this like described here:
http://www.playframework.com/documentation/2.0.4/ScalaOAuth
Unfortunately the service I'm accessing rejects POST request - which Play sends. Can I change Play's behavior to do GET requests undercover?
Looks like you'll need to write a custom method to handle GET as Play's OAuth object defers request handling to the Commons HTTP library.
Here's a link to the source code for OAuth.scala. Using Play's WS library it should be straightforward to pattern your custom HTTP call based on this:
https://github.com/playframework/playframework/blob/0c265c943a801b2cc9b65e055c956a125f072a64/framework/src/play-ws/src/main/scala/play/api/libs/oauth/OAuth.scala
How does websites like Twitter structure their server side for APIs in which there can be multiple return types?
For ex:
https://dev.twitter.com/docs/api/1.1/post/statuses/update
In this link, you can find that their example resource url is "https://api.twitter.com/1.1/statuses/update.json"
Using the ".json" extension, they differentiate between the return type. My questions basically is, if this is the method that they use, then do parse the url and get the extension using normal string manipulation, or is their a built in support in REST that is capable of doing so.
Also, is it better to have multiple APIs for multiple return types, or can there be a single API that can have multiple return types?
In Java, the specification JAX-RS provides the #Produces annotation. Setting
#Produces("application/json")
on a method will make this method match any request with the HTTP header
Accept: application/json
Obviously Twitter is doing something else. With JAX-RS you could use path matching.
#Produces("application/json")
#Path("/1.1/statuses/update.json")
could be the annotations for a method the prodcues application/json while
#Produces("application/xml")
#Path("/1.1/statuses/update.xml")
could be the annotations that produce application/xml.
I'd advise not to go the Twitter way of putting the content type into the URI. Instead use the proper HTTP tools of content negotiation with the HTTP headers Accept and Content-Type.
This post if a follow-up question to mt previous post:
Android RESTful Web application using Zend Framework
I have written a web application which is based on the Zend Framework (Version 1.11.11) and I want to use the SAME backend code for coding the mobile version of this application (Android). To achieve this, I want to get the response for each of the actions in the controllers in XML and JSON - for mobile-based app.
Using the answers provided in the above link, I am able to get the XML and JSON response by making use of the AjaxContext helper. I set the contexts as json for the required actions in the init method and I am getting the desired json response.
Now I have another challenge. How to know from the URL if the given action was a GET or a POST request? Do I have have to add that as a query parameter? Is that the correct way?
For example, for login action within User controller: URL will be: [link] (http://localhost/user/login)
But within the loginAction, I check if the given request if a post and authenticate only if the request is a post. So the URL: http://localhost/user/login?format=xml will always return to me the response for a GET request since there is no way of knowing if the request was a GET or POST. Please help.
Thanks.
Abhilash
like you added format parameter do the same for request . Use "method" parameter to decide what type of request is it . Or you can also do is
$this->getRequest()->isPost(); //create
$this->getRequest()->isGet(); //read
$this->getRequest()->isPut(); // update
$this->getRequest()->isDelete(); // delete