Code Monkey home page Code Monkey logo

perfect's Introduction

Perfect: Server-Side Swift 简体中文

Get Involed with Perfect!

Swift 5.2 Platforms macOS | Linux License Apache

Perfect: Server-Side Swift

Perfect is a complete and powerful toolbox, framework, and application server for Linux, iOS, and macOS (OS X). It provides everything a Swift engineer needs for developing lightweight, maintainable, and scalable apps and other REST services entirely in the Swift programming language for both client-facing and server-side applications.

Perfect includes a suite of tools that will enhance your productivity as you use only one programming language to build your apps: Swift. The global development community’s most dynamic and popular server-side toolbox and framework available today, Perfect is the backbone for many live web applications and apps available on iTunes.

This guide is designed for developers at all levels of experience to get Perfect up and running quickly.

Working with Perfect

Compatibility with Swift

The master branch of this project currently compiles with Xcode 11 or the Swift 5 toolchain on Ubuntu.

Getting Started

Access a tutorial to help you get started using Perfect quickly. It includes straightforward examples of how Perfect can be used.

Documentation

Get started working with Perfect, deploy your apps, and find more detailed help by consulting our reference library.

We welcome contributions to Perfect’s documentation. If you spot a typo, bug, or other errata, or have additions or suggestions to recommend, please create a pull request or issue in Github.

Community

We all need a little help now and then. If you do too, don’t be shy, ask us or the friendly and supportive Perfect community:

Slack | Twitter

Deployment

Your Perfect project can be deployed to any Swift compatible Linux server. We provide a macOS desktop application, Perfect Assistant, to help with AWS and Google Cloud deployments. Additional deployment options are in the works.

Samples, Examples, and Tutorials

Our library continues to grow as members of the Swift-Perfect development community have shared many samples and examples of their projects in Perfect. Examples include:

There are many more examples you can explore. Please share yours!

Core Perfect Modules

Perfect project is divided into several repositories to make it easy for you to find, download, and install the components you need:

  • Perfect – This repository contains the core PerfectLib and will continue to be the main landing point for the project
  • Perfect Docs – Contains all API reference-related material

Examples

  • Perfect Template - A simple starter project which compiles with the Swift Package Manager into a standalone executable HTTP server. This repository is ideal for starting a Perfect-based project
  • Perfect Examples - All the Perfect example projects

DataSources

Utilities

More about Perfect

Perfect operates using either a standalone HTTP server, HTTPS server, or through FastCGI server. It provides a system for loading your Swift-based modules at startup, for interfacing those modules with its request/response objects, or to the built-in Mustache template processing system.

Perfect is built on a completely asynchronous, high-performance networking engine to provide a scalable option for internet services. It supports Secure Sockets Layer (SSL) encryption, and it features a suite of tools commonly required by internet servers such as WebSockets and iOS push notifications, but you are not limited to those options.

Feel free to use your favourite JSON or templating systems, etc.

Join and Contribute to the Community

The Swift-Perfect developer community is vital to improving Perfect and supporting one another.  

You can help other developers by sharing your expertise and tips, as well as learn from others, by joining the Perfect Slack channel. Contributions of all kinds are welcome: reporting issues, updating documentation, fixing bugs, building examples, sharing projects, and any other tips that may help the Swift-Perfect community.

If you would like to share your example project, tutorial, or video, please share the URL of your work on GitHub and Twitter, and the Perfect team will highlight it to the community.

Code of Conduct

The Perfect team welcomes people of all ethnicities, nationalities, ages, gender, disability, levels of experience, and religious beliefs to use and contribute to the Perfect project. We pledge to foster and enforce a harassment-free environment of openness, respect, and cooperation for everyone in all project and public spaces online or offline.

Please report any behaviour that violates our Code of Conduct to [email protected]. The Perfect team is committed to enforcing this Code of Conduct to ensure everyone who wishes to use, contribute to, and comment on the Perfect project may do so freely and openly and without fear of reprisal.

We will investigate all complaints of unacceptable or abusive behaviour or comments expediently, and we will maintain the confidentiality of the person who reports any perceived infraction or wrongdoing to us. We will not tolerate any form of direct or indirect harassment or discrimination within the Swift-Perfect community, and will take appropriate, fair, and corrective action to any instance of inappropriate behaviour.

The Perfect team maintains the right to remove, edit, or reject any comments, code, edits, or issues that do not align with our Code of Conduct.

perfect's People

Contributors

123flo321 avatar califrench avatar chris-sean avatar coderxpert avatar dabeck avatar drinking avatar gitter-badger avatar groovelab avatar iamjono avatar jezhawk avatar johnlinvc avatar kingiol avatar kjessup avatar kumuluzz avatar ludagoo avatar nerdo avatar omrd avatar petrpavlik avatar rockfordwei avatar rymcol avatar sandordobi avatar scorovit avatar seanstephens avatar shaneqi avatar taplin avatar theabstractdev avatar thislooksfun avatar tspoonman avatar willbchang avatar wuqiong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

perfect's Issues

support for web sockets and socket.io planned?

We use socket.io in our current Swift iOS app and would love to move from Node.js to perfect.

Please consider adding socket.io support into your plans. A roadmap of features (and a place to vote for your favorite) would be a great addition to this project.

Mark Classes as final

Optimizes code to C++, level performance.

Also, in the MySQL class, you would not want that to be subclassed, and the internal pointer should be private.

The file "TapTracker" was not found.

i built the server and module, run the server:
1

then i tap the button in Tap Tracker APP, its get this response:
Request succeeded with data Optional("The file "/TapTracker" was not found.")
JSON decoding failed with exception SyntaxError("Malformed boolean literal")

how can i resolve it?

Docker image

Hi there,

I'm one of the contributors to https://github.com/swiftdocker/docker-swift. If there's any interest in vendoring a docker image containing the suite of Perfect libraries and possibly the server (though I wonder if long term a server isn't really in your interest, given that nginx etc exist) for easy development and deployment, please let me know if I can be of any assistance!

WebRequest has no method for accessing body

The current implementation of WebRequest appears to try to assume/do too much. Particularly in the event of POSTing Content-type: application/json, I should be able to post a document body with a properly formed JSON string. Then, in my handler I can access the body directly (what appears to be request.connection.stdin but that is protected) without any "intelligence" from postParams processing.

Consistent swift coding style

Taken from this reddit comment:: https://www.reddit.com/r/swift/comments/3ttu9u/serverside_swift_is_here_its_perfect/cx9hrpc

Nice work!
I have one suggestion though - be more consistent wrt to code conventions. For example, top
level constants (from one module) are defined in
- lowercase snake case
- uppercase snake case
- camelCase
...

by 20DCCD77-E82E-4045-A

I would suggest using https://github.com/raywenderlich/swift-style-guide as your style guide. At least as a mold for a style guide. It seems to be very good.

Send data with POST / GET request

Hi,
First, thank you so much for your awesome framework.
Please help to explain how could i send data with POST / GET request from client and how to receive those params on server via Swift code ?
Many thanks for your help.

Swift NGINX Module?

A moderate feature request: Perfect has an Apache connector; it would be great to see an NGINX module too!

Moustache: empty comments cause parsing error

The following works:
{{% handler:FAHandler}}{{!
This is the moustache template file
}}{"resultSets":[{{#resultSets}}{"time":"{{time}}","lat":{{lat}},"long":{{long}} }{{^last}},{{/last}}{{/resultSets}}]}

While this causes parsing problems:

{{% handler:FAHandler}}{{!

}}{"resultSets":[{{#resultSets}}{"time":"{{time}}","lat":{{lat}},"long":{{long}} }{{^last}},{{/last}}{{/resultSets}}]}

The system skips the closing empty comment delimiters.

Benchmarks

It'd be great to see benchmarks compared to other languages and frameworks.

Getting started error: No such module PerfectLib

I am trying to get started with Perfect and just cloned the repository.

Opened up 'Authenticator' and tried to build the Authenticator Server. Got an error (No such module PerfectLib).

no such module

So, I opened up PerfectLib and tried to build it. It build :-) but gave an error of 'No umbrella header found for target 'PerfectLibOSX, module map will not be generated.

no umbrella header

After building the PerfectLib (with this warning) and going back to the Authenticator project, I still get the same error.

I suspect I missed a simple step here. Can someone suggest what I missed?

Thanks,

Charlie

Library not loaded: @rpath/libswiftAppKit.dylib

Setup:
Using the Xcode template I created a new Perfect Server Project, modified the scheme to include the executable PerfectServer HTTP.app, added PerfectLib.Framework to the linked libraries and binaries. The project runs and PerfectServerModuleInit() executes in the project.

Problem:
I was never able to get a request to the mustache template in my project, I was still able to send requests to TapTracker, Authenticator, and UploadEnumerator (login, request, TapTracker...). I went to the webroot directory and saw login, request, TapTracker... but not my mustache template. Looking deeper I ran the executable PerfectServer HTTP and the following message comes out after multitude of other messages come out

Output:
objc[4290]: Class _TtCSs18_EmptyArrayStorage is implemented in both /Users/Cam/Library/Developer/Xcode/DerivedData/Examples-aqjpcyrjmijblwavckfeldxenqlq/Build/Products/Debug/PerfectLib.framework/Versions/A/Frameworks/libswiftCore.dylib and /Users/Cam/Library/Developer/Xcode/DerivedData/Examples-aqjpcyrjmijblwavckfeldxenqlq/Build/Products/Debug/perfectserverhttp. One of the two will be used. Which one is undefined.

Errno dlopen(./PerfectLibraries/MyTestPerfectServer.framework/Versions/Current/MyTestPerfectServer, 6): Library not loaded: @rpath/libswiftAppKit.dylib
Referenced from: /Users/Cam/Library/Developer/Xcode/DerivedData/Examples-aqjpcyrjmijblwavckfeldxenqlq/Build/Products/Debug/MyTestPerfectServer.framework/Versions/Current/MyTestPerfectServer
Reason: image not found
FAILED to load MyTestPerfectServer.framework/

Suggest: use tyrone-sudeium/JSONCore instead of JSON.swift

I tried tyrone-sudeium/JSONCore, it's Foundation free. I try serialize ["ad":[["i": -41451, "i2": 41451, "d": -42E+2, "t": true, "f": false, "n": nil, "a":[1, 2, 3, 4]], ["another":"one"]]] and it works properly.
JSON.swift still have a lot of work to make it work. I think we should just use tyrone-sudeium/JSONCore for JSON parse/serialization and focus on some other Perfect module.

tvOS support

After this I feel obliged to share some of the process here. Ideally I would like to turn this into a pull request, but as my hacking isn't really ready for merging yet, I'll just share the steps I remember here, so the thinking doesn't have to be performed twice :)

  • Copied OSX target and changed the SDK to tvOS
  • Added import Foundation to some files
  • Removed SysProcess from the tvOS target
  • Built custom tvOS versions of libcurl.a libssl.a and lib crypto.a using this
  • Built custom version of libevent using this (I'm not really sure of the removal of fork in this case, but as it's only in tests, it should be okay)
  • Replaced the other libraries (libicu and libsqlite) with the tvOS versions provided by Apple

A problem that I haven't solved yet, but shouldn't be hard is that the creation of the session database currently fails, because it uses a file it can't access. This is also a theoretical problem: As we are only allowed to store cache on appleTV, does in matter if the session database gets wiped every time the app quits? Probably not, depending on your use case.

I hope I covered everything. As I said, I will try and fix this up in a PR soon!

How to run MySQLTests.swift?

How can I run MySQLTests.swift on ubuntu?

I've copied both MySQL.so and MySQL.swift to Perfect/Connectors/MySQL/MySQLTests.

When I execute swift MySQLTests.swift, I always get error: no such module 'MySQL'

PerfectLib compiled, but PerfectServer failed

Running on Ubuntu 14.04

As per the subject, PerfectLib compiled without error, but I get errors when trying to compile the Server. Error is as follows:

clang++ -L/usr/local/swift-2.2/usr/lib/swift/linux -lFoundation -lswiftCore -lswiftGlibc /usr/local/lib/PerfectLib.so -Xlinker -rpath -Xlinker /usr/local/swift-2.2/usr/lib/swift/linux perfectserverfcgi.o -o perfectserverfcgi
/usr/local/lib/PerfectLib.so: undefined reference to u_isalnum_55' /usr/local/lib/PerfectLib.so: undefined reference toudat_format_55'
/usr/local/lib/PerfectLib.so: undefined reference to udat_close_55' /usr/local/lib/PerfectLib.so: undefined reference tou_isWhitespace_55'
/usr/local/lib/PerfectLib.so: undefined reference to udat_open_55' /usr/local/lib/PerfectLib.so: undefined reference tou_errorName_55'
/usr/local/lib/PerfectLib.so: undefined reference to ucal_getNow_55' /usr/local/lib/PerfectLib.so: undefined reference toudat_parse_55'
/usr/local/lib/PerfectLib.so: undefined reference to `u_isdigit_55'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [perfectserverfcgi] Error 1

Thanks

An ExpressJs like framework.

Hi, I am planning on developing an ExpressJS like framework using swift. I was searching for a swift NetTCP library but could not find one. I like your NetTCP implementation, it is really neat. So, could you publish it as a separate swift package? Thanks in advance

Suggestion: Object mapping for JSON

Dear Kyle,

thank you first for the effort you already put into this project. I really hope that server-side Swift will take its place in the future. We need someone who start with a project like this and if people like it you will get support for sure.

Besides that i have one suggestion regarding the json serialization/deserialization.
In my projects i use ObjectMapper from Hearst as it allows me to write classes and create a mapping of static types and a JSON output or input. Also i can define custom formatters to catch an convert my content on the fly, based on the mapping i defined in my mappable classes.

It would be nice to see an approach like this as it allows us developers to rely on what we define. This kind of approach already works with AlamofireObjectMapper and makes it totally easy and safe to handle untyped data in a strongly typed world.

Thanks in advance and good luck,
Stefan

JSONEncode should use type methods or be renamed JSONEncoder

Hi everybody,

First of all I wanna thank everyone for the great work on this project. I'm so excited about being able to use swift in full stack mode!

I was browsing through the docs and came across the JSONEncode and JSONDecode classes. Initially I was thinking it would make more sense for the JSONEncode class to use type methods (a.k.a. static methods) but then I checked out the JSONDecode class and noticed it uses instance variables. So what would be more appropriate would be to rename the classes to JSONEncoder and JSONDecoder because the instances of these types will be doing the job.

I can perform a refactoring and submit a pull request. What do you guys think?

Califrench

Tap Tracker Example error

Hey, I was trying out the Perfect project and I had an error executing the target Tap Tracker in the Examples.workspace:

~/Perfect-master/PerfectLib/Utilities.swift:427:16: Use of unresolved identifier 'File'

Deploy on AWS?

I'm assuming this can't be deployed to a real production server yet, since it can't run on linux.
Is that something that is only reconcilable after Apple open sources the language?

Nevertheless, not being able to scale the servers made is definitely an issue.

Trailing URL Variables not placed in urlVariables dictionary

I would expect urlVariables to contain an entry for id in the following case:

Routing.Routes["GET", "/device/{id}"]

It doesn't. Adding a trailing component to the URL it does get populated:

Routing.Routes["GET", "/device/{id}/show"]

Extending further,

Routing.Routes["GET", "/device/{id}/show/{sub}"]

sub is not in the the urlVariables dictionary but id is.

Issue when launching the server on Ubuntu 15-10 : "the file / was not found"

Hello,

I have a problem when i launch the perfectserverhttp from Ubuntu 15-10.
capture d ecran 2015-12-14 a 17 59 00

The server launches properly, but then i can't manage to work with it. The message "The file "/" was not found" is displaying on the navigator.

Could it be because i use a virtual machine? Or did i do something wrong with the installation? I followed step by step the instructions written in the Readme files.

Thanks in advance!

Cannot build on osx, make failed

Got this after running make on el capitan, did i miss something?

:1:9: note: in file included from :1:

import "openssl/ssl.h"

    ^

/Users/zipeldiablo/Perfect/PerfectLib/linked/OpenSSL_Linux/openssl/ssl.h:146:11: note: in file included from /Users/zipeldiablo/Perfect/PerfectLib/linked/OpenSSL_Linux/openssl/ssl.h:146:

include <openssl/e_os2.h>

      ^

/Users/zipeldiablo/Perfect/PerfectLib/linked/OpenSSL_Linux/openssl/e_os2.h:56:10: error: 'openssl/opensslconf.h' file not found

include <openssl/opensslconf.h>

     ^

NetTCPSSL.swift:26:8: error: could not build Objective-C module 'OpenSSL'
import OpenSSL
^
make[1]: *** [ICU.o] Error 1
make: *** [all] Error 2

pthread_cond_timedwait_relative_np unresolved,any one can help me?

Threading.swift:99:14: error: use of unresolved identifier 'pthread_cond_timedwait_relative_np'
let ret = pthread_cond_timedwait_relative_np(&self.cond, &self.mutex, &tm);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make: *** [Threading.o] Error 1

error occur when i make

Routing

Hi, I can't find in doc. How I can handle routing with Perfect?

MySQL Connector Build Failed

Have an error on line 53 of MySQL.swift:
static private var dispatchOnce: Threading.ThreadOnce = 0
-- Cannot convert value of type'Int' to specified type 'ThreadOnce' (aka '_opaque_pthread_once_t')

no umbrella header

Great project !

But I have some question..
I clone the repo and build the PerfectLibOSX target in Examples.xcworkspace.
But then I got a warning

warning: no umbrella header found for target 'PerfectLibOSX', module map will not be generated

Is this normal?
My Xcode is Version 7.2 (7C68)

no such module "perfectlib"

main_http.swift while using XCode 7.2

Just needs the build settings modified slightly

PerfectLib -> Build Settings -> Packaging -> Defines Module

It currently defaults to No causing the error.

MYSQL / MongoDB Doc

I frenquently use MYSQL or MongoDB for my websites, APIs and other and I would like to use these with Perfect.. But we haven't docs for these Connectors

Building on Linux

I've spent the last two days trying to get a project with several dependencies compiled and running on Linux. The other projects I've been working with use the Swift Package Manager approach, a Package.swift definition file plus /Sources directory, which makes it very easy to link dependencies from their github repo URL.

Perfect on the other hand uses a makefile. It would be really nice to be able to reference PerfectLib in the same manner, but it doesn't appear the project is structured to be Swift Package Manager friendly (unless I'm missing it).

What's the prospects of getting the Perfect project structured to work with Swift Package Manager, and in the meantime, what's your recommended approach for using Perfect as a dependency for projects building on Linux?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.