Skip to content

Migration from the REST API

When using a REST API, you receive any data which that endpoint was engineered to deliver. In this example, we are using a curl command to make a GET request to one of the Meetup API REST endpoints. We are using 'meetup-pro-test-group' for our test group, and 276754274 as the example eventId.

curl https://api.meetup.com/meetup-pro-test-group/events/276754274

This would return all of the available data in an object. It's up to you how that data is used, or even IF it's used, since you may have only wanted a portion of it. If this is a large endpoint, you would be receiving much more data than you need. This is more work for you to sift through, slower for Meetup to process before delivering to you, and also slower for you to download since we are sending more data.

{
  "title": "Meetup Pro Test Group",
  "description": "This is a test group!",
  "host": {
    "id": "12345",
    "email": "h.mctesty@somedomain.com",
    "name": "Henry McTesty"
  },
  "group": "Test Group",
  "venue": {
    "id": "678910",
    "name": "Big Convention Center",
    "city": "New York",
    "country": "USA"
  },
  "dateTime": "11/10/2021 12:00:00",
  "duration": "2 hours",
  "timeZone": "EST",
  "endTime": "11/10/2021 14:00:00",
  "eventType": "Physical",
  "isOnline": "False"
}

Now let's look at how you would make a 'query' in GraphQL. This time, you've decided that you are developing an application with a simple list, which only requires a small subset of that data. There's no need to pull all of it, then sift through it like you would with REST. You can just craft a query to grab the exact pieces of data you want, like this:

query event {
  event(id: "276754274") {
    title
    description
    host {
      email
      name
    }
    dateTime
  }
}

Taking this query, and formatting it into an actual curl POST request, you wind up with this:

curl -X POST https://api.meetup.com/gql \
-H 'Authorization: Bearer {YOUR_TOKEN}' \
-H 'Content-Type: application/json' \
-d @- <<'EOF'
    {"query": "query event {
      event(id: "276754274") {
        title
        description
        host {
          email
          name
        }
        dateTime
      }
    }",
  }
EOF

You have now retrieved that small subset of data, because that is exactly what you asked for:

{
  "data": {
    "event": {
      "title": "Meetup Pro Test Group",
        "description": "This is a test group!",
        "host": {
          "email": "h.mctesty@somedomain.com",
          "name": "Henry McTesty"
        },
        "dateTime": "11/10/2021 12:00:00"
    }
  }
}

When writing GraphQL queries, they may look more complicated than a REST request at first glance, but that's a good thing! You'll soon see that the query format is easy to understand, and that the small change in work up front allows amazing customization and flexibility. In this example, you can see how we've trimmed down the data set to be exactly what we want, and nothing more. Some logic comes before the data is pulled, as opposed to after like with REST. In the end, you can assign that data to objects and variables just as you did before; you’re just starting with a cleaner, trimmed down set. Also, don't forget that this is less for Meetup to process, and faster for you to download!