简体   繁体   中英

how to use/read this curl api and add limit for data, POST method

so i got this api from my partner and i never use this kind of api format and i asked to put limit parameter so it will only recieve certain data limit. But i don't understand where to put this --data . if the method is GET it's fine i just need to add ?limit=10&page=1 in the url but for the POST method how? i usually put body:{"limit":10} for POST but now it doesn't work

  curl --request POST \
  --url https://base-url.com/api/v2/order/all/79025884 \
  --header 'Content-Type: application/json' \
  --cookie 'connect.sid=s%253ArO7T68J_dUxbwAoogHU.ezS9SwNk1gb8AgJxOUqjzoJoza9ETpE7t1TDugussQY; token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwaG9uZU51bWJlciI6IjA4MTExNzA5MjIxIiwidXNlcm5hbWUiOiJGbG8iLCJpYXQiOjE2NjE2NDI0NjcsImV4cCI62N30.8hyXmK3H0N9Iccedv9XSs6_rbtmToS8B0woxWNj9IXM' \
  --data '{
    "limit":10,
    "page":1
}'

my fetch api code

  const url = APIConfig.SERVER.ORDER + "/all/" + userID;
    fetch(url, {
      method: "POST",
      headers: { "content-type": "application/JSON" },
    })
      .then((response) => response.json())
      .then((data) => {
        setOrderList(data.data);
      })
      .catch((error) => {
        console.error("Error:", error);
      });

You can do like:

const url = APIConfig.SERVER.ORDER + "/all/" + userID;
    fetch(url, {
      method: "POST",
      headers: { "content-type": "application/JSON" },
      body: JSON.stringify({
                limit:10,
                  page:1
             })
    })
      .then((response) => response.json())
      .then((data) => {
        setOrderList(data.data);
      })
      .catch((error) => {
        console.error("Error:", error);
      });

Hope it helps, feel free for doubts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM