https://github.com/vaporexampleslab/vaporapiwebtemplate
A starting point for vapor api (Fluent) + web (Leaf) applications.
https://github.com/vaporexampleslab/vaporapiwebtemplate
swift template vapor vapor-template
Last synced: 3 months ago
JSON representation
A starting point for vapor api (Fluent) + web (Leaf) applications.
- Host: GitHub
- URL: https://github.com/vaporexampleslab/vaporapiwebtemplate
- Owner: VaporExamplesLab
- License: mit
- Created: 2017-10-16T17:05:54.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-30T22:33:54.000Z (almost 7 years ago)
- Last Synced: 2024-12-31T21:26:11.455Z (over 1 year ago)
- Topics: swift, template, vapor, vapor-template
- Language: Swift
- Homepage:
- Size: 128 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license
Awesome Lists containing this project
README
> NOTE: After an Xcode update to Swift 4.2, `NIO`, `NIOFoundationCompat`, `NIOHTTP1`, and `NIOHTTP1` warnings can be silenced by setting the `SWIFT_VERSION` to "Swift 4" in the Target build settings.
[Example Routes](#ExampleRoutes) •
[Components](#Components) •
[Use](#Use) •
[Resources](#Resources)
`VaporApiWebTemplate` is an API + Web Template (AWT) hybrid based on [vapor/api-template](https://github.com/vapor/api-template) and [vapor/web-template](https://github.com/vapor/web-template). `VaporApiWebTemplate` template uses Vapor 3, Swift 4.1 and Xcode 9.
`VaporApiWebTemplate` also includes a set of lightweight examples:
* api routes which use SQLite (`TextpostApiController`, `Textpost`)
* web page routes which serve static files from "Public/" (`FileMiddleware` enabled)
* web page routes which use Leaf templating (`LeafWebController`)
* simple custom `Middleware` (`ExampleMiddleware`)
* simple custom `Service` (`ExampleService`, `ExampleFortuneService`, `ExampleQuoteService`, `ExampleServiceProvider`)
* UUID extension for RFC 4122 compliance
* `XCTest` unit test examples
Example routes setup in the baseline template.
**Basic**
`http://localhost:8080/hello`
```
Hello, world!
```
`http://localhost:8080/hellojson`
``` JSON
{"hello":"world"}
```
`http://localhost:8080/info`
Returns a description of http request.
``` http
GET /api/info HTTP/1.1
Host: localhost:8080
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
User-Agent: …
```
**Dynamic API (Fluent)**
* `/api/textposts` POST creates one database entry for valid JSON `Textpost`.
* `/api/textposts` GET returns an array of all available `Textpost`
* `/api/textposts/uuid` GET returns one specific `Textpost`
* `/api/textposts` PUT updates an existing `Textpost` or create a new `Textpost`.
* `/api/textposts/uuid` PATCH applies partial update modification to specific `Textpost` entry.
* `/api/textposts/uuid` DELETE removes one specific `Textpost`.
**Static HTML**
* `http://localhost:8080/` redirects to '/index.html'.
* `http://localhost:8080/index.html` minimal HTML 5.
**Web HTML Templates (Leaf)**
* `http://localhost:8080/leaf` simple leaf example.
* `http://localhost:8080/leaf/hello`
* `http://localhost:8080/leaf/hello/Sunshine` leaf with a `String` parameter.
``` markup
Hello, Sunshine!
Hello, Sunshine!
```
* `http://localhost:8080/leaf/bootstrap` example page with Bootstrap, Swift data objects and Leaf.
### API Fluent
```
Sources/App/
Controllers/
TextpostController.swift
Models/
Textpost.swift
Tests/AppTests/
TextpostControllerTests.swift
```
### Web Leaf Template
Leaf templating components.
```
Sources/App/
Controllers/
LeafWebController.swift
Public/
images/it-works.png
scripts/.gitkeep
styles/app.css
Resources/
Views/
bootstrap_web.leaf
bootstrap_welcome.leaf
web_base.leaf
web_hello.leaf
Tests/AppTests/
LeafWebControllerTests.swift
```
``` bash
vapor new PROJECT_NAME --template=marc-medley/004.77_VaporApiWebTemplate
cd PROJECT_NAME
vapor update
```
Set the Xcode active scheme to `Run > My Mac`.

[Atom: language-leaf ⇗](https://atom.io/packages/language-leaf)
[Mac App Store: RESTed - Simple HTTP Requests ⇗](https://itunes.apple.com/us/app/rested-simple-http-requests/id421879749) _…free._