Description
Expected Behavior
The API returns a response
Current Behavior
The API sends back a 301 permanent redirect to the URL with a trailing slash at the end, which given the example below would be https://mit-open-rc.odl.mit.edu/api/v0/users/me/?format=json
Steps to Reproduce
- Navigate to an API endpoint like https://mit-open-rc.odl.mit.edu/api/v0/users/me?format=json
Additional Details
This was discovered while testing #429. The mit-open
API implementation in OCW is entirely done from frontend Javascript, with fetch
commands (at least for now). When performing a fetch
using a site that has to be accessed with CORS, a redirect breaks the flow. Since 3xx responses are not part of the CORS spec, the response is returned sans CORS headers. Since the request is a CORS request to begin with and the Access-Control-Allow-Origin
header is not returned by the server with the 301, the browser generates a CORS error and does not follow the redirect. In order for this strategy to work in OCW, the API URLs need to follow the exact schema the API needs, and / or the API needs to not redirect and enforce a trailing slash.