Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
How do i use an API on the P5js library?

I've been working on the p5js library and i'm trying to use an API to get access to weather data for my project, but the editor keeps throwing an error and I don't know why Here's my code:

function setup() {
  createCanvas(400,400); 
  let url = 'http://api.openweathermap.org/data/2.5/weather?q=London&appid=e7402cc176aacd446829a856f2723b57&units=metric'
  loadJSON(url,gotData)
}

function gotData(data){
  print(data);  
}

function draw(){
}

Can someone help point out what's wrong with my code?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should post the errors you're getting. (Since you were already using the p5.js editor you could also share a link so it's easier to for everyone else to replicate your issue)

I've just tried your code in the p5 web editor and I'm getting this error in the browser's JS Console:

p5.js:84555 Mixed Content: The page at 'https://editor.p5js.org/' was loaded over HTTPS, but requested an insecure resource 'http://api.openweathermap.org/data/2.5/weather?q=London&appid=e7402cc176aacd446829a856f2723b57&units=metric'. This request has been blocked; the content must be served over HTTPS.

Sometimes errors can be cryptic, but in this case it's pretty straight forward:

  • p5.js is loaded from an HTTPS domain (https://editor.p5js.org)
  • the weather API is accessed via HTTP(unsecure) (http://api.openweathermap.org/...etc.)
  • Ideally you'd load both via HTTPS (and the Weather API supports HTTPS).

This is makes the solution as simple as adding a single 's' :) (from http:// to https:// when accessing the Weather API)

function setup() {
  createCanvas(400,400); 
  let url = 'https://api.openweathermap.org/data/2.5/weather?q=London&appid=e7402cc176aacd446829a856f2723b57&units=metric'
  loadJSON(url,gotData)
}

function gotData(data){
  print(data);  
}

function draw(){
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.min.js"></script>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!