1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[84559],{47009:function(e,s,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/apis/gdp",function(){return t(18477)}])},18477:function(e,s,t){"use strict";t.r(s),t.d(s,{default:function(){return u}});var a=t(85893),r=t(67294),i=t(41664),n=t.n(i),l=t(10241),c=t(7636),o=t(15600),d=t(96503),p=t(49152);let h={curl:`curl -X GET "https://api.api-ninjas.com/v1/gdp?country=United%20States" \\ 2 -H "X-Api-Key: YOUR_API_KEY"`,python:`import requests 3 4country = 'United States' 5api_url = 'https://api.api-ninjas.com/v1/gdp?country={}'.format(country) 6response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'}) 7if response.status_code == requests.codes.ok: 8 print(response.text) 9else: 10 print("Error:", response.status_code, response.text)`,javascript:`$.ajax({ 11 method: 'GET', 12 url: 'https://api.api-ninjas.com/v1/gdp?country=Canada', 13 headers: { 'X-Api-Key': 'YOUR_API_KEY'}, 14 contentType: 'application/json', 15 success: function(result) { 16 console.log(result); 17 }, 18 error: function ajaxError(jqXHR) { 19 console.error('Error: ', jqXHR.responseText); 20 } 21});`,nodejs:`const request = require('request'); 22 23request.get({ 24 url: 'https://api.api-ninjas.com/v1/gdp?country=Canada', 25 headers: { 26 'X-Api-Key': 'YOUR_API_KEY' 27 }, 28}, function(error, response, body) { 29 if(error) return console.error('Request failed:', error); 30 else if(response.statusCode != 200) return console.error('Error:', response.statusCode, body.toString('utf8')); 31 else console.log(body) 32});`,java:`import java.io.InputStream; 33import java.net.HttpURLConnection; 34import java.net.URL; 35 36import com.fasterxml.jackson.databind.ObjectMapper; 37 38URL url = new URL("https://api.api-ninjas.com/v1/gdp?country=Canada"); 39HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 40connection.setRequestProperty("accept", "application/json"); 41InputStream responseStream = connection.getInputStream(); 42ObjectMapper mapper = new ObjectMapper(); 43JsonNode root = mapper.readTree(responseStream); 44System.out.println(root.path("gdp").asText());`,swift:`let url = URL(string: "https://api.api-ninjas.com/v1/gdp?country=Canada")! 45var request = URLRequest(url: url) 46request.setValue("YOUR_API_KEY", forHTTPHeaderField: "X-Api-Key") 47let task = URLSession.shared.dataTask(with: request) {(data, response, error) in 48 guard let data = data else { return } 49 print(String(data: data, encoding: .utf8)!) 50} 51task.resume()`},m=[{country:"CAN",year:1980,gdp_growth:2.2,gdp_nominal:276.064,gdp_per_capita_nominal:11281.422,gdp_ppp:290.29,gdp_per_capita_ppp:11862.755,gdp_ppp_share:2.192},{country:"CAN",year:1981,gdp_growth:3.5,gdp_nominal:307.246,gdp_per_capita_nominal:12396.666,gdp_ppp:328.886,gdp_per_capita_ppp:13269.808,gdp_ppp_share:2.224},"..."];class u extends r.Component{constructor(e){super(e),this.handleSubmit=this.handleSubmit.bind(this),this.state={disableSubmit:!1,base_url:"https://api.api-ninjas.com/v1/gdp",url1:"https://api.api-ninjas.com/v1/gdp",param1:"Canada",param2:"",response:m}}componentDidMount(){window.Prism?.highlightAll()}handleSubmit(){this.setState({disableSubmit:!0,response:null});let e=this.state.url1,s=[];this.state.param1&&s.push("country="+encodeURIComponent(this.state.param1)),this.state.param2&&s.push("year="+this.state.param2),s.length>0&&(e+="?"+s.join("&")),fetch(e,{headers:{"X-Api-Key":this.props.apiKey||""}}).then(e=>e.json()).then(e=>{this.setState({response:e})},e=>{}).finally(()=>{this.setState({disableSubmit:!1})}),window.gtag("event",this.state.url1.substring(27))}render(){return(0,a.jsxs)(c.Z,{title:"GDP API - API Ninjas",description:"GDP API by API Ninjas - get current and historical GDP data for any country.",sidebarName:"GDP",children:[(0,a.jsxs)("div",{className:"d-flex flex-column flex-md-row px-4",children:[(0,a.jsx)("div",{className:"w-100 flex-md-fill max-width-md-50 px-2",children:(0,a.jsx)("div",{className:"content-inner mx-auto mt-4",children:(0,a.jsx)("div",{className:"",children:(0,a.jsx)("div",{className:"section-block",children:(0,a.jsxs)("div",{id:"doc-header",className:"doc-header",children:[(0,a.jsx)("h1",{className:"doc-title",children:"GDP API"}),(0,a.jsx)("p",{children:"The GDP API provides current and historical GDP (Gross Domestic Product) data for countries around the world."})]})})})})}),(0,a.jsx)("div",{className:"w-100 flex-md-fill max-width-md-50 px-2 pt-md-4",children:(0,a.jsx)("div",{className:"w-100 section-block",children:(0,a.jsx)(l.Z,{apiId:92})})})]}),(0,a.jsx)(p.Z,{id:"gdp-endpoint",path:"/v1/gdp",children:(0,a.jsxs)("div",{className:"d-flex flex-column flex-md-row px-4",children:[(0,a.jsx)("div",{className:"w-100 flex-md-fill max-width-md-50 px-2",children:(0,a.jsx)("div",{className:"content-inner mx-auto",children:(0,a.jsx)("div",{className:"doc-section",children:(0,a.jsxs)("div",{className:"section-block",children:[(0,a.jsx)("p",{children:(0,a.jsx)("code",{children:this.state.base_url})}),(0,a.jsx)("p",{children:"Get GDP data from given parameters. Returns GDP statistics that satisfy the parameters."}),(0,a.jsxs)("div",{className:"api-block",children:[(0,a.jsx)("h4",{children:"Parameters"}),(0,a.jsxs)("p",{children:["At least one of the following parameters must be set:"," ",(0,a.jsx)("strong",{children:(0,a.jsx)("code",{children:"country"})}),","," ",(0,a.jsx)("strong",{children:(0,a.jsx)("code",{children:"year"})})]}),(0,a.jsxs)("ul",{className:"list-group api-list",children:[(0,a.jsxs)("li",{className:"list-group-item px-3 py-2 light-bg",children:[(0,a.jsxs)("h5",{className:"my-1 text-muted",children:[(0,a.jsx)("strong",{children:(0,a.jsx)("code",{children:"country"})}),"\xa0\xa0optional"]}),(0,a.jsxs)("p",{className:"my-1",children:["Country name (case-insensitive) or 2-letter ISO-3166 alpha-2 code of the country. E.g."," ",(0,a.jsx)("code",{children:"Canada"})," or ",(0,a.jsx)("code",{children:"CA"}),"."]})]}),(0,a.jsxs)("li",{className:"list-group-item px-3 py-2 light-bg",children:[(0,a.jsxs)("h5",{className:"my-1 text-muted",children:[(0,a.jsx)("strong",{children:(0,a.jsx)("code",{children:"year"})}),"\xa0\xa0optional"]}),(0,a.jsx)("p",{className:"my-1",children:"Year for which to retrieve GDP data."})]})]})]}),(0,a.jsxs)("div",{className:"api-block",children:[(0,a.jsx)("h4",{children:"Headers"}),(0,a.jsx)("ul",{className:"list-group api-list",children:(0,a.jsxs)("li",{className:"list-group-item px-3 py-2 light-bg",children:[(0,a.jsxs)("h5",{className:"my-1 text-muted",children:[(0,a.jsx)("strong",{children:(0,a.jsx)("code",{children:"X-Api-Key"})}),"\xa0\xa0required"]}),(0,a.jsx)("p",{className:"my-1",children:"API Key associated with your account."})]})})]}),(0,a.jsxs)("div",{className:"api-block",children:[(0,a.jsx)("h4",{children:"Response"}),(0,a.jsxs)("p",{className:"mb-3",children:["A JSON array of objects, each containing the following fields, or ",(0,a.jsx)(n(),{href:"/error-codes",className:"bold",children:"an error"})," if the request is unsuccessful."]}),(0,a.jsxs)("ul",{className:"list-group api-list",children:[(0,a.jsxs)("li",{className:"list-group-item px-3 py-2 light-bg",children:[(0,a.jsx)("h5",{className:"my-1 text-muted",children:(0,a.jsx)("strong",{children:(0,a.jsx)("code",{children:"country"})})}),(0,a.jsx)("p",{className:"my-1",children:"The 3-letter ISO 3166 alpha-3 country code."})]}),(0,a.jsxs)("li",{className:"list-group-item px-3 py-2 light-bg",children:[(0,a.jsx)("h5",{className:"my-1 text-muted",children:(0,a.jsx)("strong",{children:(0,a.jsx)("code",{children:"year"})})}),(0,a.jsx)("p",{className:"my-1",children:"The year for which the GDP data is recorded."})]}),(0,a.jsxs)("li",{className:"list-group-item px-3 py-2 light-bg",children:[(0,a.jsx)("h5",{className:"my-1 text-muted",children:(0,a.jsx)("strong",{children:(0,a.jsx)("code",{children:"gdp_growth"})})}),(0,a.jsx)("p",{className:"my-1",children:"GDP growth rate as a percentage."})]}),(0,a.jsxs)("li",{className:"list-group-item px-3 py-2 light-bg",children:[(0,a.jsx)("h5",{className:"my-1 text-muted",children:(0,a.jsx)("strong",{children:(0,a.jsx)("code",{children:"gdp_nominal"})})}),(0,a.jsx)("p",{className:"my-1",children:"Nominal GDP in billions of US dollars."})]}),(0,a.jsxs)("li",{className:"list-group-item px-3 py-2 light-bg",children:[(0,a.jsx)("h5",{className:"my-1 text-muted",children:(0,a.jsx)("strong",{children:(0,a.jsx)("code",{children:"gdp_per_capita_nominal"})})}),(0,a.jsx)("p",{className:"my-1",children:"Nominal GDP per capita in US dollars."})]}),(0,a.jsxs)("li",{className:"list-group-item px-3 py-2 light-bg",children:[(0,a.jsx)("h5",{className:"my-1 text-muted",children:(0,a.jsx)("strong",{children:(0,a.jsx)("code",{children:"gdp_ppp"})})}),(0,a.jsx)("p",{className:"my-1",children:"GDP at purchasing power parity (PPP) in billions of US dollars."})]}),(0,a.jsxs)("li",{className:"list-group-item px-3 py-2 light-bg",children:[(0,a.jsx)("h5",{className:"my-1 text-muted",children:(0,a.jsx)("strong",{children:(0,a.jsx)("code",{children:"gdp_per_capita_ppp"})})}),(0,a.jsx)("p",{className:"my-1",children:"GDP per capita at PPP in US dollars."})]}),(0,a.jsxs)("li",{className:"list-group-item px-3 py-2 light-bg",children:[(0,a.jsx)("h5",{className:"my-1 text-muted",children:(0,a.jsx)("strong",{children:(0,a.jsx)("code",{children:"gdp_ppp_share"})})}),(0,a.jsx)("p",{className:"my-1",children:"Country's share of world GDP at PPP as a percentage."})]})]})]})]})})})}),(0,a.jsx)("div",{className:"w-100 flex-md-fill max-width-md-50 px-2",children:(0,a.jsxs)("div",{className:"doc-section section-block content-inner",children:[(0,a.jsx)(d.Z,{hasUser:this.props.hasUser,apiKey:this.props.apiKey||"",url:this.state.url1+(this.state.param1||this.state.param2?"?"+[this.state.param1?"country="+encodeURIComponent(this.state.param1):"",this.state.param2?"year="+this.state.param2:""].filter(e=>e).join("&"):""),onSubmit:this.handleSubmit,disableSubmit:this.state.disableSubmit,response:this.state.response,defaultResponse:m,onRestore:()=>this.setState({response:m}),children:(0,a.jsxs)("div",{className:"rounded-pill mt-3",children:[(0,a.jsx)("label",{className:"sr-only",htmlFor:"inlineFormInputGroup",children:"Country"}),(0,a.jsxs)("div",{className:"input-group mb-2",children:[(0,a.jsx)("div",{className:"input-group-prepend",children:(0,a.jsx)("div",{className:"input-group-text",children:"country"})}),(0,a.jsx)("input",{id:"sample-api-request",className:"form-control api-example-query",defaultValue:this.state.param1,onChange:e=>this.setState({param1:e.currentTarget.value})})]}),(0,a.jsxs)("div",{className:"input-group mb-2",children:[(0,a.jsx)("div",{className:"input-group-prepend",children:(0,a.jsx)("div",{className:"input-group-text",children:"year"})}),(0,a.jsx)("input",{id:"sample-api-request-2",className:"form-control api-example-query",defaultValue:this.state.param2,onChange:e=>this.setState({param2:e.currentTarget.value})})]})]})}),(0,a.jsxs)("div",{id:"searchcodeexample",className:"api-block my-4",children:[(0,a.jsx)("h4",{children:"Code Examples"}),(0,a.jsx)(o.Z,{samples:h,apiKey:this.props.apiKey})]}),(0,a.jsx)("div",{children:(0,a.jsx)("p",{className:"font-14",children:"If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation."})})]})})]})})]})}}}},function(e){e.O(0,[14289,27919,71979,10241,47269,84205,49774,92888,40179],function(){return e(e.s=47009)}),_N_E=e.O()}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.