|
4 months ago | |
---|---|---|
Authentication | 4 months ago | |
Controllers | 4 months ago | |
Models | 4 months ago | |
Properties | 4 months ago | |
.gitignore | 4 months ago | |
Dockerfile | 4 months ago | |
LICENSE | 4 months ago | |
Program.cs | 4 months ago | |
README.md | 4 months ago | |
Stac.csproj | 4 months ago | |
Startup.cs | 4 months ago | |
appsettings.Development.json | 4 months ago | |
appsettings.json | 4 months ago |
AspNetCore RESTful API to return upside-down cat pictures.
angry
, sad
, beans
).NET Core CLI | Docker |
---|---|
dotnet restore |
docker build . -t stac |
dotnet run |
docker run -p 8080:80 --rm stac |
Configuration can be retreived from either appsettings.json
or Environment Variables.
JWT_SIGNING_KEY
: Signing key to generate and verify JSON web tokens. string
JWT_ISSUER
: Issuer of the token string
JWT_AUDIENCE
: Intended recipient of the token. string
JWT_VALIDITY
: Validity of the token, in minutes. int
I recommend using the interactive Swagger documentation located at the root node: /
.
If the CLI is your style, try: HTTPpie & HTTPie-JWT.
Register a new User
POST /user username=<username> password=<password>
Sign In
POST /authentication/signin username=<username> password=<password>
Enjoy upside-down cat pictures
GET /image/cat
GET /image/cat?tag=beans
Try JWT
GET /authentication/jwt
GET /image/cat Bearer=<token>
├── Controllers
│ ├── Authentication
│ │ └── AuthenticationController.cs
│ ├── User
│ │ └── UserController.cs
│ └── ImageController.cs
├── Models
│ └── UserInformation.cs
├── Program.cs
└── Startup.cs
For me, defining a directory structure is an important decision when beginning a new project. An intuitive structure aids the development process by making components painless to find and modify.
In this project the directory names are based on the RESTful API design, for example /authentication => Controllers/Authentication
- This design helps determine what class is responsible for particular HTTP routes.
I have attempted to write as little code as possible, placing an importance on layout and readability which makes the project easily accessible to future developers.
Where possible, I have researched and integrated relevant packages. Utilizing these pre-existing solutions saves time, reduces code complexity and delegates maintenance to the respective package authors.
One concrete example is the image manipulation library - Instead of creating a function to flip the cat image, I opted for ImageSharp.
Well defined guidelines regarding commits and their messages add a new informational dimension to a project, one that helps paint a picture of how and why code has changed.
I emphasize:
Open a cat image using a JWT.
$ T=<token>
$ http --auth-type=jwt --auth="${T}" localhost:8080/image/cat --output cat && xdg-open cat
Get UserInformation
using a JWT.
$ T=<token>
$ http --auth-type=jwt --auth="${T}" localhost:8080/user