DeveloperBreeze

Api Development Development Tutorials, Guides & Insights

Unlock 4+ expert-curated api development tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your api development skills on DeveloperBreeze.

Getting Started with Pydantic: Data Validation and Type Coercion in Python

Tutorial August 29, 2024
python

Pydantic can also be used to manage application settings by reading from environment variables:

from pydantic import BaseSettings

class Settings(BaseSettings):
    app_name: str = "My App"
    admin_email: str

    class Config:
        env_prefix = "MYAPP_"

settings = Settings()
print(settings.app_name)
print(settings.admin_email)

Building a RESTful API with Go and Gorilla Mux

Tutorial August 12, 2024
go

In this tutorial, we built a simple RESTful API using Go and Gorilla Mux. We covered:

  • Setting up a Go project with Gorilla Mux.
  • Defining models and handling JSON data.
  • Implementing basic CRUD operations.
  • Testing the API using curl or Postman.

Building a GraphQL API with Node.js and Apollo Server

Tutorial August 12, 2024
javascript nodejs graphql

const { ApolloServer, gql, PubSub } = require('apollo-server-express');
const pubsub = new PubSub();

const BOOK_ADDED = 'BOOK_ADDED';

const typeDefs = gql`
    type Book {
        title: String!
        author: String!
    }

    type Query {
        books: [Book]
    }

    type Mutation {
        addBook(title: String!, author: String!): Book
    }

    type Subscription {
        bookAdded: Book
    }
`;

const resolvers = {
    Query: {
        books: () => books,
    },
    Mutation: {
        addBook: (_, { title, author }) => {
            const newBook = { title, author };
            books.push(newBook);
            pubsub.publish(BOOK_ADDED, { bookAdded: newBook });
            return newBook;
        },
    },
    Subscription: {
        bookAdded: {
            subscribe: () => pubsub.asyncIterator([BOOK_ADDED]),
        },
    },
};

const server = new ApolloServer({
    typeDefs,
    resolvers,
    subscriptions: {
        path: '/subscriptions',
    },
});

const app = express();
server.applyMiddleware({ app });

const httpServer = require('http').createServer(app);
server.installSubscriptionHandlers(httpServer);

httpServer.listen({ port: 4000 }, () => {
    console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`);
    console.log(`🚀 Subscriptions ready at ws://localhost:4000${server.subscriptionsPath}`);
});

In the GraphQL Playground, you can test the subscription by running the following:

Creating a Simple REST API with Flask

Tutorial August 03, 2024
python

  • Get a specific item:
  curl http://127.0.0.1:5000/api/items/1