I have an api and frontend I'm trying to connect.
The frontend and API are deployed on a kubernetes cluster. I'm calling a GET method to populate some data and the data is not being loaded from the api. I checked the method call from chrome and the API url is appended twice.
For example, a successful GET request to my API to load this data would be example.app.com/users and the url chrome is showing in debug for the GET request is example.app.com/example.app.com/users.
I verified the API GET method works and returns the data I need. Any idea what I might be doing wrong?
Are you passing "example.app.com/users" to the function that executes the GET API?
If you pass "/users", does the result work as you expect?
Related
I am using OKTA default APIs( /api/v1/users/${userId}/sessions) for closing session across all the devices. The functionality is working as expected but the status is showing the API call is failed.
And also when we validate through Postman the 204 response code is returning but in angularjs the API call is failing.
Below is the API reference page which I have used in my application
https://developer.okta.com/docs/reference/api/users/#user-sessions
Please find the attached screenshot for your reference
Postman Response
There are few OKTA APIs which will support backend only for security reasons. So I have added client.endAllUserSessions(user.id)" method in my backend to remove user session across all devices. It is working fine for me.
(/api/v1/users/${userId}/sessions) API is failed in front end So we should call the "client.endAllUserSessions(user.id)" method in backend(Node JS) to clear user session.
For older okta-sdk-nodejs versions We Should call "client.endAllUserSessions(user.id)" method. For latest okta-sdk-nodejs versions We Should call "client.clearUserSessions(user.id)" method.
Thanks,
Subash.E
I created a simple REST API with express and bodyParser which returns a json object on a GET request to the base url. Works fine in the browser and returns what's expected:
API Endpoint: https://jk9j0.sse.codesandbox.io/.
Code: https://codesandbox.io/s/magical-montalcini-jk9j0
Then I setup a basic react app to consume this API by sending a GET request with axios. But on calling the API endpoint above, I get no response. Trying to catch the error.request object, I don't see anything that's clearly incorrect in the headers. The error object itself says 'Network Error'. Not sure why, when the API works as expected in a browser.
Note: When I replace my API url with another one, which is expected to send a similar response, things work great.
The one that works: https://jsonplaceholder.typicode.com/posts/
I haven't created that one, but used it to model my json object.
React Code: https://codesandbox.io/s/hungry-sun-rq94r
I've tried investigating from several angles but no luck. What am I missing here? Do I need to set some headers in the request? Is this a CORS issue?
Yes, it turned out to be a CORS issue. Had to apply header in the API end-point before sending response. res.header("Access-Control-Allow-Origin", "*").
To make a long story short, I'm building a server-rendered Express / React application and I'm trying to query the back-end, from the client, for some data. The basic flow looks like this:
User navigates to a client path applications/:id
The Application component is loaded
A GET request is made to the server's API from the Application component lifecycle method componentWillMount
The data from the response is added to Redux
The problem is that the response (step 4) is a 401 (Unauthorized). This is not an issue of being logged in or not. A valid session exists and if I navigate to the API route from the browser, I can see the expected response. As an added note, this application is similar to another application (in nearly ever relevant aspect), which does not have this issue.
Attempted troubleshooting steps:
Verified correct modules and versions
Verified correct API request path and configuration (using Axios and withCredentials config param)
Verified server routing and authentication
Verified PassportJS config
Verified the request session is being lost in the auth process
As it turns out, the problem was that I was making the API request from the componentWillMount React lifecycle method. In other words, since the component in question was being rendered on the server and wasn't yet complete, the API call was being made from the server side as well (the component had not yet mounted), meaning the cookie was not available for the API request. Hence the 401 Unauthorized error.
Reading the docs first would have saved me quite a bit of trouble:
componentWillMount() ...
Avoid introducing any side-effects or subscriptions in this method. For those use cases, use componentDidMount() instead.
This is the only lifecycle hook called on server rendering.
I have a redirect set up made with Switcheroo that redirect calls from an api server to my local one. The redirect is something like mydomain.com/api/* to localhost:3000/api/. The web app is implemented using angular and all the calls are made by angular services. I don't think angular is involved btw.
The calls are redirected to a Nodejs local server.
When I directly use to browser and I point it to the redirected api url (mydomain.com/api/somedata) I get the correct response. The network panel show me the first call to mydomain.com with a 307 Internal Redirect response, and then the second call to my local server with 200 OK response. Everything works fine and I can see the response in the Response panel of the redirected call..
When I go online I see the exact same two calls but I apparently do not receive any data from the server since the response panel is just showing "The request has no response data available". I know for sure that the redirect is landing to my local server since I see the server logs and when I change the response status the browser receives it.
What can I do? Could be an angular problem since the calls are made by anguar services? I really don't think so but I really don't understand why this happen.
Thanks for your consideration.
I want to save data using AngularJS and RestApi. I am sending an object in data parameter.
I tried both $http.post() direct method and $http() method , but non of these are working.
Always the error coming is "Method not allowed-405"
I am running on local machine.
Edit:
Eventually by doing some modifications like I specified "localhost:xxx" before the 'api/abc', now I am getting the error as "The requested resource does not support the http method 'POST'".
The reason is that the API you're using does not support POST requests to the URL you're trying to POST to
More info from http://www.checkupdown.com/status/E405.html below
All Web servers can be configured to allow or disallow any method. For example if a Web server is 'read-only' (no client can modify URL resources on the Web server), then it could be set up to disallow the PUT and DELETE methods. Similarly if there is no user input (all the Web pages are static), then the POST method could be disallowed. So 405 errors can arise because the Web server is not configured to take data from the client at all.