Scaffolds out API files and projects based on a given template file in a json or yaml format.
craftsman new:api [options] <filepath>| Argument | Description |
|---|---|
| filepath | The full filepath for the yaml or json file that describes your web API using a proper Wrapt format. |
| Option | Description |
|---|---|
| -h, --help | Display help message. No filepath is needed to display the help message. |
craftsman new:api -h
craftsman new:api C:\fullpath\api.yaml
craftsman new:api C:\fullpath\api.yml
craftsman new:api C:\fullpath\api.jsonTo get things started, you're going to need to scaffold out what you want your initial API configuration to look like in a yaml or json file.
Don't feel pressured to get this exactly correct from the get go. This file is NOT meant to be a concrete implementation of your API, just a starting point that you can build on over time.
So what's this file look like? For a full list of the configuration option details, you can go to the configuration file options, but let's go over a basic yaml example:
First, you need to start with a name for your API:
SolutionName: VetClinic.ApiThen, let's layout the database context:
SolutionName: VetClinic.Api
DbContext:
ContextName: VetClinicContext
DatabaseName: VetClinic
Provider: SqlServerThen, we'll add an entity (check out the full list of entity options):
SolutionName: VetClinic.Api
DbContext:
ContextName: VetClinicContext
DatabaseName: VetClinic
Provider: SqlServer
Entities:
- Name: Pet
Properties:
- Name: PetId
IsPrimaryKey: true
Type: int
CanFilter: false
- Name: Name
Type: string
CanFilter: false
- Name: Type
Type: string
CanFilter: false
CanSort: trueNote that this is a list, so we can add more than one entity if we want:
SolutionName: VetClinic.Api
DbContext:
ContextName: VetClinicContext
DatabaseName: VetClinic
Provider: SqlServer
Entities:
- Name: Pet
Properties:
- Name: PetId
IsPrimaryKey: true
Type: int
CanFilter: false
- Name: Name
Type: string
CanFilter: false
- Name: Type
Type: string
CanFilter: false
CanSort: true
- Name: City
Plural: Cities
Properties:
- Name: CityId
CanManipulate: false
Type: int
CanFilter: true
- Name: Name
Type: string
CanFilter: false And that's it! Now that we've laid out what we want our API to look like, let's make it!
To actually create our API, you'll want to cd into whatever directory you want to add your project to:
cd C:\MyFull\RepoPath\HereThen, let's make sure that our Foundation.Api template and Craftsman CLI are up to date:
dotnet new foundation.api --update-apply
dotnet tool update -g craftsmanThen we just need to add our yaml or json path to our craftsman new:api command:
craftsman new:api C:\Users\Paul\Documents\ApiConfigs\VetClinic.yamlOnce you've run this command, your API should be ready to go!
👀 Docs Feedback
See something missing or light in content in the docs? Let me know! I want the Wrapt docs to be as through and helpful as possible!
If you'd like to request a new feature, you can submit a new Craftsman issue.