# API Builder

## APIBuilder

This static class enables users to create an API specification using both custom specifications as well as specifications derived from Postman integration. Most notably, it provides a way to fully generate a complete Web API given an APISpecification.

### From

This method allows users to manually build an API Specification using a fluent syntax.&#x20;

You can easily add endpoints after declaring the specification like so:

#### Example:

```csharp
//Declare spec
var spec = APIBuilder.From("ProjectName", AuthorizationType.Bearer, true, true);

//Add as many endpoints, in this example, an echo endpoint
spec.AddEndpoints(
  APIGeneration.Endpoint.From(spec, "Echo", "/echo", APIGeneration.Method.GET)
    .WithRequestJSON(@"{""echo"": ""message""}")
    .WithAIAssistance("Echo the message back to the use in json"));
```

### FromPostman

This method allows users to build an API Specification from Postman. This is useful for integrating existing Postman collections into new or existing projects.&#x20;

{% hint style="warning" %}
If your collection contains **{{environment variables}}**, please supply the environment.json as well as the collection.json.
{% endhint %}

#### Example:

```csharp
APIBuilder.FromPostman("ProjectName", "PostmanCollection.json", "env.json");
```

### GenerateAPI

This method generates a full web API given an APISpecification. It requires the specification object, the project path, as well as optional parameters for IIS, HTTP and HTTPS Ports, additional installs, additional App Settings, a GPT Token and Model for generative AI, and boolean flags for generating Controller and Method summaries.

#### Example:

```csharp
APIBuilder.GenerateAPI(spec, "ProjectPath", 60978, 7181, 7182, additionalInstalls, additionalAppSettings, "GPTToken", "gpt-4", true, false);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.perigee.software/api-generation/api-builder.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
