---
title: Load Data from Web Services
product: Form Library
description: View free demo for JavaScript and learn how to load data to a web form using RESTful API.
framework: React
source: https://surveyjs.io/form-library/examples/dropdown-menu-load-data-from-restful-service/reactjs
index: https://surveyjs.io/form-library/examples/overview.md
---

# Load Data from Web Services (React)

SurveyJS Form Library allows you to populate drop-down menus with data loaded from a REST API web service. For this purpose, drop-down form fields include the [`choicesByUrl`](https://surveyjs.io/form-library/documentation/api-reference/dropdown-menu-model#choicesByUrl) property.<!-- cut --> It accepts an object with the following properties:

- `url`: string     
A RESTful service's URL. It may include [placeholders](https://surveyjs.io/form-library/documentation/design-survey/conditional-logic#dynamic-texts) that allow you to use question values as URL query parameters (see the `reg_country` question in this demo).

- `valueName`: string       
Specifies which field contains choice values.

- `titleName`: string       
Specifies which field contains display texts for choice values.

- `path`: string       
A path to the array of choices. Specify `path` only if the array of choices is nested within the object returned by the service. The following path separators are allowed: semicolon (`;`), comma (`,`).

When you use `choicesByUrl`, the form field queries an entire dataset in a single request. This technique may decrease performance on large datasets. In this case, we recommend that you implement [lazy loading](https://surveyjs.io/form-library/examples/lazy-loading-dropdown/).

## Files

### `public/index.html`

```html
<div id="surveyElement" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; min-height: 100%; height:100%"></div>
```

### `src/SurveyComponent.jsx`

```js
import React from "react";
import { Model } from "survey-core";
import { Survey } from "survey-react-ui";
import "survey-core/survey-core.min.css";
import "./index.css";
import { json } from "./json";

function SurveyComponent() {
    const survey = new Model(json);
    survey.onComplete.add((sender, options) => {
        console.log(JSON.stringify(sender.data, null, 3));
    });
    return (<Survey model={survey} />);
}

export default SurveyComponent;
```

### `src/index.css`

```css
/* You can add your custom CSS here. */
```

### `src/index.js`

```js
import React from "react";
import { createRoot } from "react-dom/client";
import SurveyComponent from "./SurveyComponent";

const root = createRoot(document.getElementById("surveyElement"));
root.render(<SurveyComponent />);
```

### `src/json.js`

```js
export const json = {
  "elements": [{
    "type": "dropdown",
    "name": "country",
    "title": "Select a country",
    "description": "A full list of countries is queried from a RESTful web service.",
    "choicesByUrl": {
      "url": "https://surveyjs.io/api/CountriesExample",
      "valueName": "name"
    }
  }, {
    "type": "panel",
    "name": "countriesByRegion",
    "title": "Filter countries by selected region",
    "description": "Only countries from the selected region are queried.",
    "elements": [{
      "type": "dropdown",
      "name": "region",
      "title": "Select a region",
      "choices": ["Africa", "Americas", "Asia", "Europe", "Oceania"]
    }, {
      "type": "dropdown",
      "name": "reg_country",
      "title": "Select a country",
      "choicesByUrl": {
        "url": "https://surveyjs.io/api/CountriesExample?region={region}",
        "valueName": "name"
      }
    }]
  }]
};
```

### `src/theme.js`

```js
export const themeJson = {};
```

### `package.json`

```json
{
  "dependencies": {
    "react": "latest",
    "react-dom": "latest",
    "survey-core": "latest",
    "survey-react-ui": "latest"
  },
  "devDependencies": {
    "react-scripts": "latest"
  }
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/form-library/examples/dropdown-menu-load-data-from-restful-service/angular.md)
- [Vue 3](https://surveyjs.io/form-library/examples/dropdown-menu-load-data-from-restful-service/vue3js.md)
- [jQuery](https://surveyjs.io/form-library/examples/dropdown-menu-load-data-from-restful-service/jquery.md)
- [Vanilla JS](https://surveyjs.io/form-library/examples/dropdown-menu-load-data-from-restful-service/vanillajs.md)
