Flip cat images upside down - Programming Test
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
Arran 48888f1b1d Improve Readme formatting 11 months ago
Authentication Add JWT Authentication 11 months ago
Controllers Add JWT Authentication 11 months ago
Models Add JWT Authentication 11 months ago
Properties Add ImageController and basic project skeleton 11 months ago
.gitignore Initial Commit - Add GitIgnore 11 months ago
Dockerfile Add Docker support 11 months ago
LICENSE Add LICENSE 11 months ago
Program.cs Remove unnecessary 'using' statements 11 months ago
README.md Improve Readme formatting 11 months ago
Stac.csproj Add JWT Authentication 11 months ago
Startup.cs Define explicit password requirements 11 months ago
appsettings.Development.json Add JWT Authentication 11 months ago
appsettings.json Add JWT Authentication 11 months ago

README.md

Stac (Cats) 🐈

AspNetCore RESTful API to return upside-down cat pictures.

Features

  • Authenticated access to upside-down cat pictures with tag support! eg. (angry, sad, beans)
  • Interactive Swagger Documentation
  • Simultaneous Cookie and JWT Authentication

Running

.NET Core CLI Docker
dotnet restore docker build . -t stac
dotnet run docker run -p 8080:80 --rm stac

Environment Variables / Configuration

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

Quick Start

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>

Development Notes

Project Structure

├── 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.

Project Philosophy

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.

Git

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:

  • Including concise, well defined changes.
  • Using an imperative mood in commit messages.
  • Capitalizing the beginning of the subject line.

Code Snippets

HTTPie

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