Passing GET-Request-parameters In Header
So, I am in the process of learning JavaScript and was wondering whether I could use a custom header field of a GET request to pass certain parameters to tell the Node-Server how to handle the data passed in the URL.
As I understand, this is not standard practice, but are there actually technical reasons that would prohibit such a use case?
Answer
It is possible to pass the actions via Headers to the Server.
Though it is not in practice because it brings security risks to the application. Complete control of operation is with the Client and Clients can be compromised to do some malicious activity.
The whole point of having a Back End in between your app data and your client is to mitigate the security risks by having more control over the operation.
One thumb rule that you can continue with: The Clint (The Website, Apps etc) are dumb and its the responsibility of Server to take preventive measures.
That's why passing operations via headers could be dangerous.
But if you are asking operations like Add, Delete, Update etc; you can use REST API specs. This gives you different type of HTTP request for different kind of operations.
- GET - Read
- POST - Create
- PUT - Update
- DELETE - Delete
And response can be a good readable message and/or HTTP Codes like
- 200 - Ok
- 404 - Not Found
- 403 - Unauthorized
- 204 - Ok but no content
More descriptive list: https://httpstatuses.com/
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM