APIs Displaying the Content

I think the api is updated for all breeds objects

The api for all breeds is updated and now the function to add the options in select menu is broken. If someone can have a look and update the code please.

3 Answers

Lewis Marshall
Lewis Marshall
22,670 Points

This API endpoint still works fine https://dog.ceo/api/breeds/list but I couldn't find it on the Dog API docs.

The new api url for all breeds is: https://dog.ceo/api/breeds/list/all I have got all breed object using the following code:

    .then(response => response.json())
    .then(data => {
        const dataMessage = data.message;
        const messageKeys = Object.keys(dataMessage);

after that the generateOptions function:

function generationOptions(data) {
    let options = "";
    data.map(item => {
        options += `
        <option value='${item}'>${item}</option>`;
    select.innerHTML = options;

Sure, they will be many better ways, but thats I could come up with at the moment. Hope its helpful if anyone else had the same issue recently.

Paul Brubaker
Paul Brubaker
14,254 Points

The API does indeed seem to be updated with a nested structure that includes sub-breeds for the all breeds list. The following code solves the problem:

function generateOptions(data) {
  let breedsList = [];
  let html = '';
  Object.keys(data).forEach(breed => {
    if (data[breed].length === 0) {
    } else {
    data[breed].forEach(subBreed => {
  breedsList.forEach(breed => {
    let readableBreed;
    if (breed.includes('/')) {
      readableBreed = `${breed.split('/')[1]} ${breed.split('/')[0]}`;
    } else {
      readableBreed = breed;
    html += `<option value=${breed}>${readableBreed}</option>`
  select.innerHTML = html;