[TIL] axios get method & query string

JIEUN YANG·2023년 2월 3일
0

While using a Axios library, I had no doubt how it makes query string itself. Just sending parameters inside of Object as a second parameter lets it call ‘GET’ request with Axios.

So after searching what happens inside, The thing is this. It’s because Axios serializes option.params which is the second parameter and add it to the query string as shown below.

import axios from 'axios'

const params = {page : 1, size : 100, itemNumber : 234}
axios.get('https://axios.test.com/', { params } )

//parameters are translateed into the query string
axios.get('https://axios.test.com/request?page=1&size=2&itemNumber=234')

To long story short, Serializer is a bulit in axios's function so that developers don't need to parse each parameter to query string.
Once all parameters are included in Object GET method parse them into query string through 'toJSON()'


Mastering axios

profile
violet's development note

0개의 댓글