https://github.com/pyrite-framework/pyrite-server-validations
pyrite-server validation plugin
https://github.com/pyrite-framework/pyrite-server-validations
pyrite-server validation
Last synced: 12 months ago
JSON representation
pyrite-server validation plugin
- Host: GitHub
- URL: https://github.com/pyrite-framework/pyrite-server-validations
- Owner: pyrite-framework
- License: mit
- Created: 2017-10-11T11:39:13.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-18T22:57:28.000Z (over 8 years ago)
- Last Synced: 2025-04-13T10:14:59.144Z (about 1 year ago)
- Topics: pyrite-server, validation
- Language: TypeScript
- Homepage: http://www.pyritejs.org
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pyrite-server-validations
- More information about object config in [https://validatejs.org/](https://validatejs.org/)
## Install
- Decorators feature has to be enabled.
```
npm install pyrite-server
npm install pyrite-server-validations
```
## Example
### main.js
```typescript
import { PyriteServer } from "pyrite-server";
import { ValidationPlugin } from "pyrite-server-validations";
const server = new PyriteServer({
port: 8000,
routes: "/routes",
plugins: [new ValidationPlugin()]
});
server.listen(() => {
console.log("Server running!");
});
```
### /routes folder:
### users.js
```typescript
import { Route, Post, Body } from "pyrite-server";
import { Validation } from "pyrite-server-validations";
const createValidation = {
username: {
format: {
pattern: "[a-z0-9]+",
flags: "i",
message: "can only contain a-z and 0-9"
}
},
password: {
presence: true
}
};
const users = [];
let index = 0;
@Route("/users")
export class Users {
@Post("/")
@Validation(createValidation)
createUser(@Body user) {
user.id = index++;
users.push(user);
return user;
}
}
```