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

If the data doesn't meet the model's requirements, Pydantic raises a ValidationError:

from pydantic import ValidationError

try:
    user = User(id="abc", name="John Doe", age="25")
except ValidationError as e:
    print(e)

Building a RESTful API with Go and Gorilla Mux

Tutorial August 12, 2024
go

Add the updateBook function to main.go:

func updateBook(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	params := mux.Vars(r)
	for index, item := range books {
		if item.ID == params["id"] {
			books = append(books[:index], books[index+1:]...)
			var book Book
			_ = json.NewDecoder(r.Body).Decode(&book)
			book.ID = params["id"]
			books = append(books, book)
			json.NewEncoder(w).Encode(book)
			return
		}
	}
	json.NewEncoder(w).Encode(books)
}

Building a GraphQL API with Node.js and Apollo Server

Tutorial August 12, 2024
javascript nodejs graphql

Modify the schema to include a query for fetching a book by title:

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

    type Query {
        books: [Book]
        bookByTitle(title: String!): Book
    }

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

const resolvers = {
    Query: {
        books: () => books,
        bookByTitle: (_, { title }) => books.find(book => book.title === title),
    },
    Mutation: {
        addBook: (_, { title, author }) => {
            const newBook = { title, author };
            books.push(newBook);
            return newBook;
        },
    },
};

Creating a Simple REST API with Flask

Tutorial August 03, 2024
python

Run the application:

python app.py