Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

 What is API?

It is used to provide data communication from one application to another, API will be developed by any server-side script such as Java, Python, PHP, NODE, etc.


What is RestAPI?

RestAPI is used to transfer the data using the HTTP method and return output data into JSON format.

It provides better performance as compare to SOAP-based API.

REST means Representation state transfer-based API.



How to write code on REST API services implementation?

1) AXIOX

2)  Fetch


now we implement an example of the Fetch API method of React JS to show data in tabular format.


Step1st:-


1)  Create a Component and Write the following code. of React Js



import React from "react";


export class RestApiCall extends React.Component{


    constructor()

    {

        super();

        this.state = {

           tdata:[]      

         }

   

    }

    componentDidMount() {

        fetch('http://jsonplaceholder.typicode.com/todos')

        .then(res => res.json())

        .then((data) => {

          this.setState({ tdata: data })

          console.log(this.state.tdata)

        })

        .catch(console.log)

      }

    render()

    {

        return(

            <div>

           <table border='1'>


           <tbody>

               <tr><th>Userid</th><th>ID</th><th>Title</th></tr>

               {this.state.tdata.map((person,i)=> <TableRow Key={i} data={person} />)}   

           </tbody>


           </table>



            </div>

        )

        

    }


}


class TableRow extends React.Component {

    render() {

       return (

          <tr>

             <td>{this.props.data.userId}</td>

             <td>{this.props.data.id}</td>

             <td>{this.props.data.title}</td>

             

          </tr>

       );

    }

 }

 








Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post