Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sroehrl/neoan3-demo-api
A starting point for API backends based on PHP.
https://github.com/sroehrl/neoan3-demo-api
api generator jwt jwt-authentication jwt-token php7 stateless
Last synced: 8 days ago
JSON representation
A starting point for API backends based on PHP.
- Host: GitHub
- URL: https://github.com/sroehrl/neoan3-demo-api
- Owner: sroehrl
- License: mit
- Created: 2020-07-26T00:33:40.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-11T01:16:11.000Z (about 3 years ago)
- Last Synced: 2024-04-19T06:21:54.182Z (7 months ago)
- Topics: api, generator, jwt, jwt-authentication, jwt-token, php7, stateless
- Language: PHP
- Homepage:
- Size: 41 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# neoan3 PHP api scaffolding
Quick & dirty api scaffolding as a result of a [twitch.tv/neoan3](https://twitch.tv/neoan3) session
### What is this?
Create your backend in seconds and add your endpoints via command line. You **don't** need a database,
this tool ships with a file-based database for your convenience. However, you can easily add a database at any point.Out of the box, you have
- user registration
- user login/authentication
- JWT / stateless authentication endpoints
- development server## Installation
**NOTE:** requires [neoan3-cli](https://github.com/neoan3/cli), PHP & composer
to be globally available.1. `composer create-project sroehrl/scaffold-api`
2. `neoan3 develop`That's it, your project should run.
## Usage
Within the project directory, run`php scaffold ` to generate get & post endpoints.
Modifications (or additional methods) to the endpoint can be achieved by editing the generated model & component files.
Look into [neoan3](https://neoan3.rocks) for specifics.## user model
This project already ships with a user model & endpoints.
_To register_
**POST /api.v1/users**
```json
{
"userName": "name82",
"password": "123456",
"whatever": "any-key-value-pair"
}
```
_response format:_
```json
{
"user": {
"userName": "name82",
"_id": "id-with-high-entropy"
},
"token": "JWT-token"
}
```All generated calls require a JWT-token to be used.
```javascript
// e.g. axios
const config = {
headers: { Authorization: `Bearer ${token}` }
};axios.get('http://localhost:8080/api.v1/test/1',{},config).then(...)
```
_to login_**POST /api.v1/users/auth**
expects same json-format (userName, password) as register, returns same format.
### Examples
`php scaffold posts`
Generates the following endpoints:
**POST /api.v1/posts** creates new post
**GET /api.v1/posts** returns multiple posts; accepts optional parameters (e.g. ?title=first)
**GET /api.v1/posts/:id** retrieves a post
**PUT /api.v1/posts/:id** updates a post
```javascript
// e.g. axios
const config = {
headers: { Authorization: `Bearer ${token}` }
};
const endpoint = "http://localhost:8080/api.v1/posts";// create post
axios.post(endpoint, {
title: "my first post",
content: "What a day!",
gitHubLink: "https://github.com/sroehrl",
author: "neoan"
},config).then(res => {
const post = res.data;
// get all posts by neoan
axios.get(endpoint + '?author=neoan',{},config).then(res => {
const allPosts = res.data;
})
})
```## The big picture
Instead of generating a pure test-api, the setup is meant to upcycle,
meaning the structure is solid. You can build out actual database implementation while providing immediate usability.