# I need help creating a Restful API app

**URL:** <https://forum.kirupa.com/t/i-need-help-creating-a-restful-api-app/639966>\
**Category:** Uncategorized\
**Created:** [June 21, 2019, 9:23pm UTC](https://forum.kirupa.com/t/i-need-help-creating-a-restful-api-app/639966 "2019-06-21T21:23:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![fast\_developer](https://avatars.discourse-cdn.com/v4/letter/f/e9bcb4/32.png) [@fast\_developer](https://forum.kirupa.com/u/fast_developer)\
**Post date:** [June 21, 2019, 9:23pm UTC](https://forum.kirupa.com/t/i-need-help-creating-a-restful-api-app/639966/1 "2019-06-21T21:23:54Z")

</div>

Hi,

I need help creating a Restful API app I’ve included the information here [http://jsonplaceholder.typicode.com/](http://jsonplaceholder.typicode.com/) . Any suggestions how to code the API would appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [June 22, 2019, 2:37am UTC](https://forum.kirupa.com/t/i-need-help-creating-a-restful-api-app/639966/2 "2019-06-22T02:37:45Z")

</div>

Are you trying to create an app that uses the API? If so, here is a tutorial using React (which I’m assuming you are using based on your earlier question) that can help you out: [https://www.kirupa.com/react/working\_with\_external\_data.htm](https://www.kirupa.com/react/working_with_external_data.htm)

🧢

---

<div class="post-metadata">

**Author:** ![fast\_developer](https://avatars.discourse-cdn.com/v4/letter/f/e9bcb4/32.png) [@fast\_developer](https://forum.kirupa.com/u/fast_developer)\
**Post date:** [June 22, 2019, 8:55am UTC](https://forum.kirupa.com/t/i-need-help-creating-a-restful-api-app/639966/3 "2019-06-22T08:55:24Z")

</div>

Yes I am trying to create an app that uses an api. I’m onto this tutorial, thanks.

---

<div class="post-metadata">

**Author:** ![fast\_developer](https://avatars.discourse-cdn.com/v4/letter/f/e9bcb4/32.png) [@fast\_developer](https://forum.kirupa.com/u/fast_developer)\
**Post date:** [June 23, 2019, 5:37pm UTC](https://forum.kirupa.com/t/i-need-help-creating-a-restful-api-app/639966/4 "2019-06-23T17:37:18Z")

</div>

Hi Kirupa,

Following the tutorial you kindly posted me, I just have a quick question. Has anyone found this problem and if so I would be grateful for suggestions. When I run the code I get a undefined error:

./src/IPAddressContainer.js  
Line 27: ‘componentDidMount’ is not defined no-undef  
Line 39: ‘processRequest’ is not defined no-undef

Search for the keywords to learn more about each error.

But I have to to remove the {} from the code in order to avoid any errors in the script:

}

```
}

```

componentDidMount()  
xhr = new XMLHttpRequest();  
xhr.open(“GET”,“[https://ipinfo.io/json](https://ipinfo.io/json)”, true);  
xhr.send();

```
   xhr.addEventListener("readystate", this.processRequest, false)

```

processRequest()  
if (xhr.readyState === 4 && xhr.status === 220)  
var response = JSON.parse(xhr.repsonseText);

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [June 24, 2019, 2:31am UTC](https://forum.kirupa.com/t/i-need-help-creating-a-restful-api-app/639966/5 "2019-06-24T02:31:20Z")

</div>

You shouldn’t remove the `{ }` from the code 🙂

Can you post your full code for IPAddressContainer.js? Add the brackets back as well, for they are an important part of how JavaScript makes sense of the structure of your code.

---

<div class="post-metadata">

**Author:** ![fast\_developer](https://avatars.discourse-cdn.com/v4/letter/f/e9bcb4/32.png) [@fast\_developer](https://forum.kirupa.com/u/fast_developer)\
**Post date:** [June 24, 2019, 8:12am UTC](https://forum.kirupa.com/t/i-need-help-creating-a-restful-api-app/639966/6 "2019-06-24T08:12:29Z")

</div>

Here is the code for IPAdddress.js

```
import React, { Component } from "react";
import "./IPAddress.css";
import "./IPAddress.js";

var xhr; 

class IPAdressContainerr extends Component {
    construtor(props, context){
        super(props, context);

    

     this.state = {
         ip_address: ".."
     }; 
      
    

     this.processRequest = this.processRequest.bind(this);
    }

    }

   componentDidMount(){
       xhr = new XMLHttpRequest(); 
       xhr.open("GET","https://ipinfo.io/json", true); 
       xhr.send();

   
   
       xhr.addEventListener("readystate", this.processRequest, false)
   }
   
   

   processRequest(){
       if (xhr.readyState === 4 && xhr.status === 220)
           var response = JSON.parse(xhr.repsonseText); 

       
    render() {
        return(
    this.setState({
        ip_address: response.ip
    });

   }
   
   }
```

---

<div class="post-metadata">

**Author:** ![fast\_developer](https://avatars.discourse-cdn.com/v4/letter/f/e9bcb4/32.png) [@fast\_developer](https://forum.kirupa.com/u/fast_developer)\
**Post date:** [June 24, 2019, 5:45pm UTC](https://forum.kirupa.com/t/i-need-help-creating-a-restful-api-app/639966/7 "2019-06-24T17:45:14Z")

</div>

Hi Kiprua,  
I wondered if you have had a chance to look through the code I posted, I would be really grateful for you help.  
Thanks in advance,

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [June 24, 2019, 6:43pm UTC](https://forum.kirupa.com/t/i-need-help-creating-a-restful-api-app/639966/8 "2019-06-24T18:43:51Z")

</div>

Hey fast\_developer - yes, I just looked at it. The biggest area is around ensuring brackets are in the right places. For example, you have an extra bracket right after the `constructor` function that closes your `class` declaration earlier than it needs to.

Take a look at the code for this in Github: [https://github.com/kirupa/kirupa/blob/master/reactjs/external\_data\_ipaddress/src/IPAddressContainer.js](https://github.com/kirupa/kirupa/blob/master/reactjs/external_data_ipaddress/src/IPAddressContainer.js)

---

<div class="post-metadata">

**Author:** ![fast\_developer](https://avatars.discourse-cdn.com/v4/letter/f/e9bcb4/32.png) [@fast\_developer](https://forum.kirupa.com/u/fast_developer)\
**Post date:** [June 24, 2019, 7:22pm UTC](https://forum.kirupa.com/t/i-need-help-creating-a-restful-api-app/639966/9 "2019-06-24T19:22:08Z")

</div>

Hi Kirupa,  
Apologies for typing your name incorrectly and I would like to personally thank you for your most excellent and prompt help with this.  
I will always return to your forum in the future for advice because it is the best advice I have come across on any Web Developer’s forums that I have tried in the past. Wishing you a good evening and thank you once more.  
fast-developer  
London, England

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [June 24, 2019, 7:59pm UTC](https://forum.kirupa.com/t/i-need-help-creating-a-restful-api-app/639966/10 "2019-06-24T19:59:42Z")

</div>

No problem at all haha. We are all here to help, so feel free to ask any questions - big or small 🙂
