๐ช๐ต๐ฎ๐ ๐ถ๐ ๐๐ฟ๐ผ๐๐-๐ข๐ฟ๐ถ๐ด๐ถ๐ป ๐ฅ๐ฒ๐๐ผ๐๐ฟ๐ฐ๐ฒ ๐ฆ๐ต๐ฎ๐ฟ๐ถ๐ป๐ด (๐๐ข๐ฅ๐ฆ)?
Browsers use CORS, a method, to prevent websites from requesting data from different URLs. A request from a browser includes an origin header in the request message. The browser allows it if it gets to the server of the exact origin; if not, the browser blocks it.
We can deal with CORS issues on the backend. Cross-origin requests require that the values for origin and ๐๐ฐ๐ฐ๐ฒ๐๐-๐๐ผ๐ป๐๐ฟ๐ผ๐น-๐๐น๐น๐ผ๐-๐ข๐ฟ๐ถ๐ด๐ถ๐ป in the response headers match and it is set by the server. When you add an origin to the backend code, the CORS middleware only permits this URL to communicate with other origins and utilize it for cross-origin resource requests.
There are two ways to fix CORS issues:
๐ญ. ๐๐ผ๐ป๐ณ๐ถ๐ด๐๐ฟ๐ฒ ๐๐ต๐ฒ ๐๐ฎ๐ฐ๐ธ๐ฒ๐ป๐ฑ ๐๐ผ ๐๐น๐น๐ผ๐ ๐๐ข๐ฅ๐ฆ
Server can let all domains with ๐๐ฐ๐ฐ๐ฒ๐๐-๐๐ผ๐ป๐๐ฟ๐ผ๐น-๐๐น๐น๐ผ๐-๐ข๐ฟ๐ถ๐ด๐ถ๐ป: *. This actually turns off same-origin policy, which is not recommended. Another option would be only to allow particular domain, which is better option, e.g., ๐๐ฐ๐ฐ๐ฒ๐๐-๐๐ผ๐ป๐๐ฟ๐ผ๐น-๐๐น๐น๐ผ๐-๐ข๐ฟ๐ถ๐ด๐ถ๐ป: ๐ต๐๐๐ฝ๐://๐๐ผ๐บ๐ฒ๐ฑ๐ผ๐บ๐ฎ๐ถ๐ป.๐ฐ๐ผ๐บ.
๐ฎ. ๐จ๐๐ฒ ๐ฎ ๐ฃ๐ฟ๐ผ๐ ๐ ๐ฆ๐ฒ๐ฟ๐๐ฒ๐ฟ
We can use a proxy server to call external API. It acts as a middleware between client and the server. If server doesn't return proper headers defined by CORS, we can add then in the proxy.
#softwareengineering #programming #api #apidesign
Browsers use CORS, a method, to prevent websites from requesting data from different URLs. A request from a browser includes an origin header in the request message. The browser allows it if it gets to the server of the exact origin; if not, the browser blocks it.
We can deal with CORS issues on the backend. Cross-origin requests require that the values for origin and ๐๐ฐ๐ฐ๐ฒ๐๐-๐๐ผ๐ป๐๐ฟ๐ผ๐น-๐๐น๐น๐ผ๐-๐ข๐ฟ๐ถ๐ด๐ถ๐ป in the response headers match and it is set by the server. When you add an origin to the backend code, the CORS middleware only permits this URL to communicate with other origins and utilize it for cross-origin resource requests.
There are two ways to fix CORS issues:
๐ญ. ๐๐ผ๐ป๐ณ๐ถ๐ด๐๐ฟ๐ฒ ๐๐ต๐ฒ ๐๐ฎ๐ฐ๐ธ๐ฒ๐ป๐ฑ ๐๐ผ ๐๐น๐น๐ผ๐ ๐๐ข๐ฅ๐ฆ
Server can let all domains with ๐๐ฐ๐ฐ๐ฒ๐๐-๐๐ผ๐ป๐๐ฟ๐ผ๐น-๐๐น๐น๐ผ๐-๐ข๐ฟ๐ถ๐ด๐ถ๐ป: *. This actually turns off same-origin policy, which is not recommended. Another option would be only to allow particular domain, which is better option, e.g., ๐๐ฐ๐ฐ๐ฒ๐๐-๐๐ผ๐ป๐๐ฟ๐ผ๐น-๐๐น๐น๐ผ๐-๐ข๐ฟ๐ถ๐ด๐ถ๐ป: ๐ต๐๐๐ฝ๐://๐๐ผ๐บ๐ฒ๐ฑ๐ผ๐บ๐ฎ๐ถ๐ป.๐ฐ๐ผ๐บ.
๐ฎ. ๐จ๐๐ฒ ๐ฎ ๐ฃ๐ฟ๐ผ๐ ๐ ๐ฆ๐ฒ๐ฟ๐๐ฒ๐ฟ
We can use a proxy server to call external API. It acts as a middleware between client and the server. If server doesn't return proper headers defined by CORS, we can add then in the proxy.
#softwareengineering #programming #api #apidesign
Forwarded from Aman Raj
Elements :- it is a javascript object
it is used in the document that are represented Html tags <p> , <div> <span>
attributes :- properties of elements which can be manipulated or accessed ex:- id class style or src
span tag:- inline container
used to markup text , documents
manipulation of css with the help of javascript
outline css :-it is used to create line around html elements
syntax :- element {outline :<outline-style><outline-width><outline-color>;}
div {outline :solid 10px #000000;}
inline css:- style attributes of html elements
used to apply unique styling to a single elements
it is used to directly define within the start tag
example :- <p style ="color:red; font-size :10px ;width:20px"> This is a paragraph </p>
Html tags :- define the structure & content of web-page
<html>
<head>
<title> My webpage </title>
</head>
<body>
<h1> welcome to my webpage </h1>
<p> welcome to my webpage </p>
<ul>
<li> first item </li>
<li> Second item </li>
</ul>
<a href ="http://www.example.com">Link to another page </a>
</body>
</html>
selectors in css ?
used to select html elements that you want to style
or you can say patterns used to identify the elements you want to style
id selctors :- can be used only on tags defined with id attributes
class selectors :- can be used only on tags defined with class attributes
universal selectors :- can be used on all elements on the defined page
this keyword in javascript?
refer the object it belongs to
it can be used inside the function
it can be used to access the objects properties and methods
let and var keyword difference
var is function scoped (this means var can be accessed outside the block it is declared in )VARIABLE HOISTING
let is block scoped ( this means let can be accessed inside the block it is decalred in ) NOT ALLOWED VARIABLE HOISTING
Components :- it is a building block of react application
these are reusable piece of code that can be composed to create complex user interface
for-of :- looping construct used to iterate over an iterable object
such as array , string , set
var String =
for(const letter of string){
console.log(letter);
}
for-each :- looping construct used to iterate over an collection of object
it is used to iterate on each collection
example:- var array =[1,2,3,4,5];
array.forEach(function(item){
console.log(item);
}
forms in html is used to take input from user
it consists of checkbox , radio buttons or select buttons
action
method
target response coming from server will be displayed
enctype type of encoding used to submit the form data
autocomplete whether or not form data will be saved by browser or not
novalidate whether or not form data will be validated by browser or not
accept-charset it will specify the character encoding used to submit form data
DOM :- it is a library
it gives specific methods
it is the entry point for working with dom in react
it reduces the amount of time used to render for a page
when we want to switch from one statement or to break the loop or label the statement
example for(let i = 0; i<100;i++){
if (i===5){
break;}
console.log(i)}
// output : 0,1,2,3,4
it is used in the document that are represented Html tags <p> , <div> <span>
attributes :- properties of elements which can be manipulated or accessed ex:- id class style or src
span tag:- inline container
used to markup text , documents
manipulation of css with the help of javascript
outline css :-it is used to create line around html elements
syntax :- element {outline :<outline-style><outline-width><outline-color>;}
div {outline :solid 10px #000000;}
inline css:- style attributes of html elements
used to apply unique styling to a single elements
it is used to directly define within the start tag
example :- <p style ="color:red; font-size :10px ;width:20px"> This is a paragraph </p>
Html tags :- define the structure & content of web-page
<html>
<head>
<title> My webpage </title>
</head>
<body>
<h1> welcome to my webpage </h1>
<p> welcome to my webpage </p>
<ul>
<li> first item </li>
<li> Second item </li>
</ul>
<a href ="http://www.example.com">Link to another page </a>
</body>
</html>
selectors in css ?
used to select html elements that you want to style
or you can say patterns used to identify the elements you want to style
id selctors :- can be used only on tags defined with id attributes
class selectors :- can be used only on tags defined with class attributes
universal selectors :- can be used on all elements on the defined page
this keyword in javascript?
refer the object it belongs to
it can be used inside the function
it can be used to access the objects properties and methods
let and var keyword difference
var is function scoped (this means var can be accessed outside the block it is declared in )VARIABLE HOISTING
let is block scoped ( this means let can be accessed inside the block it is decalred in ) NOT ALLOWED VARIABLE HOISTING
Components :- it is a building block of react application
these are reusable piece of code that can be composed to create complex user interface
for-of :- looping construct used to iterate over an iterable object
such as array , string , set
var String =
hello; for(const letter of string){
console.log(letter);
}
for-each :- looping construct used to iterate over an collection of object
it is used to iterate on each collection
example:- var array =[1,2,3,4,5];
array.forEach(function(item){
console.log(item);
}
forms in html is used to take input from user
it consists of checkbox , radio buttons or select buttons
action
method
target response coming from server will be displayed
enctype type of encoding used to submit the form data
autocomplete whether or not form data will be saved by browser or not
novalidate whether or not form data will be validated by browser or not
accept-charset it will specify the character encoding used to submit form data
DOM :- it is a library
it gives specific methods
it is the entry point for working with dom in react
it reduces the amount of time used to render for a page
when we want to switch from one statement or to break the loop or label the statement
example for(let i = 0; i<100;i++){
if (i===5){
break;}
console.log(i)}
// output : 0,1,2,3,4
๐1