From the course: Programming Foundations: APIs and Web Services
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Creating with GraphQL - Python Tutorial
From the course: Programming Foundations: APIs and Web Services
Creating with GraphQL
- APIs have traditionally followed a rigid structure with REST. GraphQL flips the script by giving clients the power to define exactly what data they need. Let's move beyond theory, and set up a GraphQL server using Python and Graphene, the most popular GraphQL framework for Python. Graphene simplifies GraphQL implementation in Python by providing tools to define schemas, queries, and mutations. Let's say you're building a GraphQL API for managing books. The first step is defining a book type, and that's shown here on lines 12 through 14. This type represents the data structure that clients can query. There is a title for our book and an author, and this means when a client sends in a request for data, they'll receive results formatted as this book object type. Next, let's define the queries. A query in GraphQL is like asking for information. Let's look at this query class here on lines 27 and 28. There are two fields, first book and books. book returns a single book, and books…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.