How to call nested apis in Springboot - rest

Assume we have an api - /student/getStudentDetails/{id} which returns a JSON response containing the succeeding internal rest api (/student/getAdvancedStudentDetails/{id}).
{
id:123,
name:Alex,
nextapi:/student/getAdvancedStudentDetails/123
}
Here when we get the response from first api - /student/getStudentDetails, we need to process the JSON response and take out the second api from the first api and call it.
Any suggestions?

Your first response for first api "GET student details" only returns high level details of student and one of field "nextapi" in response has URL to GET more details about student.
In Your first response "nextapi" is customer field defined by you and it only has
URL without host and port details of sever. So Consumer of api, will have to parse First response. Create full http url and call the next api to get further details of student. It will not happen automatically.
eg http://localhost:8080/student/getAdvancedStudentDetails/123
{
id:123,
name:Alex,
nextapi:/student/getAdvancedStudentDetails/123
}
Note :
If your response had full http url for get advance details of student and if api was not secure api. Then if you view first Json, it might give you link for next api, which you can click and see advance details. You can give it try.

Related

Data Factory Web task - getting full output from a post

I am passing json data to a post request via a web task.
The body contains a number of records that are to be saved by the api.
The body returned contains a status per record sent, but within the webtask i cannot see the over all status of the post request.
In postman, the overall status shows up like below:
This status and response code (429 in this case) is not visible in the output of the webtask.
Is anyone aware if i can view this in the webtask, as its clearly visible via postman.
Thanks,
I don't believe there's any way to get this; some time ago the MS response was to create a fn app to capture it and call that from adf :)
However you can at least distinguish 2xx from 4xx by using the On Success and On Failure dependencies in the pipeline

How to call an backend api and fetch result to show on react admin dashboard?

I have an API for my backend which gives some JSON data in response. React Admin allow data to be shown using a DATA provider. I have tried all the data provider but none of them give me the results.
I have this API Method:
GET http://localhost:8081/customer/status/{phone_no}
which gives response as :
[
{
"mobile_number": "98160******",
"status": true
}
]
So here I want to get this data in my list view and show it on the dashboard. Is there any way to do this. I have also used the jsonDataProvider. It is not also working.
I need this to be fixed very soon. If someone know how to do that pls ping.
What error is it giving you? Use the developer tools to see the errors.
Most of the time, it is probably that you need to add Content-Range header to your API:
See below documentation from the Data Providers section:
Note: The simple REST client expects the API to include a Content-Range header in the response to getList calls. The value must be the total number of resources in the collection. This allows react-admin to know how many pages of resources there are in total, and build the pagination controls.
Content-Range: posts 0-24/319
If your API is on another domain as the JS code, you’ll need to whitelist this header with an Access-Control-Expose-Headers CORS header.
Access-Control-Expose-Headers: Content-Range
Thanks

Cannot access previous response in repository with DHC

I use DHC by Reslet a Chrome extension, version 1.2.
When I create a first POST request to create an entity
If I want to access to this request in a another request (repository feature) I cannot access the response.
I have the same problem with DELETE requests, but not for GET requests
I'm not sure to correctly understand what you want to do but I'll try to give you an answer.
Imagine I want to execute the following:
POST request to add a company using the URL /companies and get its identifier from the response
GET request to get the newly created company using the identifier from the previous request
To do that I need to save the first request. I save it with the name 1 - Add company under the project Company project and the service CRUD service:
Company project
CRUD service
1 - Add company
Here is what I can use within the second request within its URL field:
contactsapi.apispark.net/v1/companies/{"Company project"
."CRUD scenario"."1 - Add company".response.body.id}
This way DHC will use the value of the id field in the response body from the latest executed 1 - Add company request in the history.

How to code the Web Api Route, Controller for texting

I need to create a REST API Web Service using MVC4 Web Api that will be consumed by Twilio. I need to be able to accept Twilio's HTTP POST for receiving SMS from the user and for responding. So if the user texts a word "Join" or "My Order" then they would call my API using the URL that I have given and I should be sending the Welcome Message for join and the Order List for the text "My Order" and so on. How the heck do I do that? Do I need a single controller or multiple? How would I route this? Please help. Totally lost :-(
Twilio evangelist here.
Twilios HTTP requests are no different than any other HTTP client. So if you want to use Web API as your Twilio SMS URL, then you would just create a Post method and in the method definition, specify the parameters you want to capture from the request.
Twilio sends along a bunch if info with each request, like the to & from phone numbers and the body of the message. You can use model binding to grab this:
public HttpResponseMessage Post(string Body) {
//your code here
// if you want to return TwiML commands, use
// us the TwilioResponse object
return Request.CreateResponse(HttpStatusCode.OK, [your twiml]);
}
Twilio will made its request with an Accept header of text/xml, so WEb API should automatically try to return your TwiML commands as XML.
This blog post has more details on using Web API with Twilio:
http://www.twilio.com/blog/2012/11/building-twilio-apps-using-asp-net-mvc-4-web-api.html
Hope that helps.

Zend Based REST URI for POST and PUT methods

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