Google Antigravity Directory

The #1 directory for Google Antigravity prompts, rules, workflows & MCP servers. Optimized for Gemini 3 agentic development.

Resources

PromptsMCP ServersAntigravity RulesGEMINI.md GuideBest Practices

Company

Submit PromptAntigravityAI.directory

Popular Prompts

Next.js 14 App RouterReact TypeScriptTypeScript AdvancedFastAPI GuideDocker Best Practices

Legal

Privacy PolicyTerms of ServiceContact Us
Featured on FazierVerified on Verified ToolsFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowFeatured on FazierVerified on Verified ToolsFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App Show

© 2026 Antigravity AI Directory. All rights reserved.

The #1 directory for Google Antigravity IDE

This website is not affiliated with, endorsed by, or associated with Google LLC. "Google" and "Gemini" are trademarks of Google LLC.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
Ky HTTP Client Patterns

Ky HTTP Client Patterns

Master Ky HTTP client patterns for Google Antigravity IDE elegant API requests

KyHTTP ClientAPITypeScript
by Antigravity AI
⭐0Stars
👁️1Views
.antigravity
# Ky HTTP Client Patterns for Google Antigravity IDE

Build elegant HTTP requests with Ky using Google Antigravity IDE. This guide covers configuration, interceptors, retry logic, and type-safe API clients.

## Client Configuration

```typescript
// src/lib/api.ts
import ky from "ky";

export const api = ky.create({
  prefixUrl: process.env.NEXT_PUBLIC_API_URL,
  timeout: 30000,
  retry: {
    limit: 3,
    methods: ["get", "put", "delete"],
    statusCodes: [408, 413, 429, 500, 502, 503, 504],
    backoffLimit: 3000,
  },
  hooks: {
    beforeRequest: [
      (request) => {
        const token = getAuthToken();
        if (token) {
          request.headers.set("Authorization", "Bearer " + token);
        }
      },
    ],
    beforeRetry: [
      async ({ request, options, error, retryCount }) => {
        console.log("Retrying request:", retryCount, error.message);
      },
    ],
    afterResponse: [
      async (request, options, response) => {
        if (response.status === 401) {
          const refreshed = await refreshToken();
          if (refreshed) {
            request.headers.set("Authorization", "Bearer " + refreshed);
            return ky(request, options);
          }
          window.location.href = "/login";
        }
        return response;
      },
    ],
    beforeError: [
      async (error) => {
        const { response } = error;
        if (response) {
          const body = await response.json().catch(() => ({}));
          error.message = body.message || error.message;
        }
        return error;
      },
    ],
  },
});
```

## Type-Safe API Client

```typescript
// src/api/users.ts
import { api } from "@/lib/api";
import type { User, CreateUser, UpdateUser } from "@/types";

export const usersApi = {
  list: async (params?: { page?: number; limit?: number; search?: string }) => {
    const searchParams = new URLSearchParams();
    if (params?.page) searchParams.set("page", String(params.page));
    if (params?.limit) searchParams.set("limit", String(params.limit));
    if (params?.search) searchParams.set("q", params.search);

    return api.get("users", { searchParams }).json<{ users: User[]; total: number }>();
  },

  get: async (id: string) => {
    return api.get("users/" + id).json<User>();
  },

  create: async (data: CreateUser) => {
    return api.post("users", { json: data }).json<User>();
  },

  update: async (id: string, data: UpdateUser) => {
    return api.patch("users/" + id, { json: data }).json<User>();
  },

  delete: async (id: string) => {
    await api.delete("users/" + id);
  },

  uploadAvatar: async (id: string, file: File) => {
    const formData = new FormData();
    formData.append("avatar", file);
    return api.post("users/" + id + "/avatar", { body: formData }).json<{ avatarUrl: string }>();
  },
};
```

## React Query Integration

```typescript
// src/hooks/useUsers.ts
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { usersApi } from "@/api/users";

export function useUsers(params?: { page?: number; search?: string }) {
  return useQuery({
    queryKey: ["users", params],
    queryFn: () => usersApi.list(params),
  });
}

export function useUser(id: string) {
  return useQuery({
    queryKey: ["users", id],
    queryFn: () => usersApi.get(id),
    enabled: !!id,
  });
}

export function useCreateUser() {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: usersApi.create,
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ["users"] });
    },
  });
}

export function useUpdateUser() {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: ({ id, data }: { id: string; data: UpdateUser }) => usersApi.update(id, data),
    onSuccess: (user) => {
      queryClient.setQueryData(["users", user.id], user);
      queryClient.invalidateQueries({ queryKey: ["users"] });
    },
  });
}
```

## Best Practices for Google Antigravity IDE

When using Ky with Google Antigravity, configure retry logic for resilience. Use hooks for auth token refresh. Create type-safe API clients. Integrate with React Query for caching. Let Gemini 3 generate API clients from OpenAPI specs.

Google Antigravity excels at building robust HTTP clients with Ky.

When to Use This Prompt

This Ky prompt is ideal for developers working on:

  • Ky applications requiring modern best practices and optimal performance
  • Projects that need production-ready Ky code with proper error handling
  • Teams looking to standardize their ky development workflow
  • Developers wanting to learn industry-standard Ky patterns and techniques

By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their ky implementations.

How to Use

  1. Copy the prompt - Click the copy button above to copy the entire prompt to your clipboard
  2. Paste into your AI assistant - Use with Claude, ChatGPT, Cursor, or any AI coding tool
  3. Customize as needed - Adjust the prompt based on your specific requirements
  4. Review the output - Always review generated code for security and correctness
💡 Pro Tip: For best results, provide context about your project structure and any specific constraints or preferences you have.

Best Practices

  • ✓ Always review generated code for security vulnerabilities before deploying
  • ✓ Test the Ky code in a development environment first
  • ✓ Customize the prompt output to match your project's coding standards
  • ✓ Keep your AI assistant's context window in mind for complex requirements
  • ✓ Version control your prompts alongside your code for reproducibility

Frequently Asked Questions

Can I use this Ky prompt commercially?

Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.

Which AI assistants work best with this prompt?

This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.

How do I customize this prompt for my specific needs?

You can modify the prompt by adding specific requirements, constraints, or preferences. For Ky projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...