Today I have learned API in javascript

 The GET method

The GET method is used to retrieve data from the server. This is a read-only method, so it has no risk of mutating or corrupting the data. For example, if we call the get method on our API, we’ll get back a list of all to-dos.

  getcall = async () => {
        //api call to get all cpt data
        const headers = {
          "Content-Type": "application/json",
          Authorization: `Bearer ${this.state.accesstoken}`,
        };
        // eslint-disable-next-line
        const res = await axios
          .get(`${ip}/head`, { headers: headers })
          .then((res) => {
            this.setState({
              cptdata: res.data.cpt,
            });
          })
          .catch((err) => {});
      };
Output:

The DELETE method

The DELETE method is used to delete a resource specified by its URI.


deletecall = async () => {
        //api call to get all cpt data
        const headers = {
          "Content-Type": "application/json",
          Authorization: `Bearer ${this.state.accesstoken}`,
        };
        // eslint-disable-next-line
        const res = await axios
          .delete(`${ip}/delete`, { headers: headers })
          .then((res) => {
            this.setState({
              cptdata: res.data.cpt,
            });
          })
          .catch((err) => {});
      };
Output:



Comments

Popular posts from this blog

Building a Full-Stack Student Management System with React.js and NestJS

Today I have solved the problem in javascript

Today I have solved problem in javascript