Code2API: A Tool for Generating Reusable APIs from Stack Overflow Code Snippets

📅 2025-04-19
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
Stack Overflow hosts vast quantities of unstructured, non-executable code snippets that lack standardization, hindering direct reuse and integration into software projects. Method: This paper introduces APIzation—a novel task that automatically transforms such fragmented code into callable, testable, standardized APIs. We propose the first LLM-powered Chrome extension specifically designed for this task, integrating chain-of-thought (CoT) reasoning and few-shot learning to emulate developer expertise in method naming, parameter inference, and return-logic generation. Contribution/Results: Compared to conventional rule-based approaches, our method achieves significant improvements in functional correctness and engineering usability on real-world Stack Overflow code snippets. It enables end-to-end, browser-native, instantaneous API generation—marking the first solution of its kind. This work establishes a new, automated, low-error paradigm for community-driven code reuse, substantially lowering barriers to practical snippet integration.

Technology Category

Application Category

📝 Abstract
Nowadays, developers often turn to Stack Overflow for solutions to daily problems, however, these code snippets are partial code that cannot be tested and verified properly. One way to test these code snippets is to transform them into APIs (Application Program Interface) that developers can be directly invoked and executed. However, it is often costly and error-prone for developers to manually perform this transformation (referred to as AIPzation task) due to different actions to be taken (e.g., summarizing proper method names, inferring input parameters list and return statements). To help developers quickly reuse code snippets in Stack Overflow, in this paper, we propose Code2API, a Google Chrome extension that uses Large Language Models (LLMs) to automatically perform APIzation of code snippets on Stack Overflow. oolname guides LLMs through well-designed prompts to generate reusable APIs, using Chain-of-Thought reasoning and few-shot in-context learning to help LLMs understand and solve the APIzation task in a developer-like manner. The evaluation results show that Code2API significantly outperforms the rule-based approach by a large margin.
Problem

Research questions and friction points this paper is trying to address.

Automate API generation from Stack Overflow code snippets
Reduce manual effort in transforming snippets to reusable APIs
Improve accuracy in API creation using LLMs and prompts
Innovation

Methods, ideas, or system contributions that make the work stand out.

Automates API generation from Stack Overflow snippets
Uses LLMs with Chain-of-Thought reasoning
Chrome extension for developer-friendly APIzation
🔎 Similar Papers
No similar papers found.
Y
Yubo Mai
Zhejiang University, China
Zhipeng Gao
Zhipeng Gao
Zhejiang University
software engineering
X
Xing Hu
Zhejiang University, China
Lingfeng Bao
Lingfeng Bao
Zhejiang University
Software Engineering
J
Jingyuan Chen
Zhejiang University, China
J
Jianling Sun
Zhejiang University, China