Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 32 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,52 @@
![](https://heatbadger.now.sh/github/readme/contributte/api-skeleton/)
# API Skeleton

<p align=center>
<a href="https://github.com/contributte/api-skeleton/actions"><img src="https://badgen.net/github/checks/contributte/api-skeleton/master"></a>
<a href="https://coveralls.io/r/contributte/api-skeleton"><img src="https://badgen.net/coveralls/c/github/contributte/api-skeleton"></a>
<a href="https://packagist.org/packages/contributte/api-skeleton"><img src="https://badgen.net/packagist/dm/contributte/api-skeleton"></a>
<a href="https://packagist.org/packages/contributte/api-skeleton"><img src="https://badgen.net/packagist/v/contributte/api-skeleton"></a>
</p>
<p align=center>
<a href="https://packagist.org/packages/contributte/api-skeleton"><img src="https://badgen.net/packagist/php/contributte/api-skeleton"></a>
<a href="https://github.com/contributte/api-skeleton"><img src="https://badgen.net/github/license/contributte/api-skeleton"></a>
<a href="https://bit.ly/ctteg"><img src="https://badgen.net/badge/support/gitter/cyan"></a>
<a href="https://bit.ly/cttfo"><img src="https://badgen.net/badge/support/forum/yellow"></a>
<a href="https://contributte.org/partners.html"><img src="https://badgen.net/badge/sponsor/donations/F96854"></a>
</p>
Example native Nette API project using [contributte/api](https://github.com/contributte/api).

<p align=center>
Website 🚀 <a href="https://contributte.org">contributte.org</a> | Contact 👨🏻‍💻 <a href="https://f3l1x.io">f3l1x.io</a> | Twitter 🐦 <a href="https://twitter.com/contributte">@contributte</a>
</p>
## Requirements

<p align=center>
<img src="https://api.microlink.io?url=https%3A%2F%2Fexamples.contributte.org%2Fapi-skeleton%2F&overlay.browser=light&screenshot=true&meta=false&embed=screenshot.url"></img>
</p>
- PHP 8.4 or newer
- [Composer](https://getcomposer.org/)

-----
## Create the native Nette API

## Goal

Main goal is to provide example of native API to [Nette](https://nette.org).

## Demo

https://examples.contributte.org/api-skeleton/

## Installation

You will need `PHP 8.4+` and [Composer](https://getcomposer.org/).

Create project using composer.
Create the distributed project, copy its local configuration, and prepare writable runtime directories:

```bash
composer create-project -s dev contributte/api-skeleton acme
composer create-project contributte/api-skeleton acme
cd acme
cp config/local.neon.example config/local.neon
mkdir -p var/tmp var/log
chmod 0777 var/tmp var/log
```

Now you have application installed. It's time to run it.

## Startup
The package distribution excludes the repository `Makefile`, so setup uses the direct commands above. Composer already installs dependencies during project creation.

The easiest way is to use php built-in web server.
## Run and verify the API

```bash
make dev
# php -S 0.0.0.0:8000 -t www
NETTE_DEBUG=1 NETTE_ENV=dev php -S 0.0.0.0:8000 -t www www/index.php
```

Then visit [http://localhost:8000](http://localhost:8000) in your browser.
Passing `www/index.php` as the router lets the PHP development server handle API paths; the repository `make dev` target omits it. The server listens on <http://localhost:8000>. In another terminal, verify it:

**API endpoints**

- http://localhost:8000/api/_/ping
- http://localhost:8000/api/_/apidoc
- http://localhost:8000/api/v1/product
- http://localhost:8000/api/v1/product/123456

## Development
```bash
curl http://localhost:8000/api/_/ping
# pong
```

See [how to contribute](https://contributte.org/contributing.html) to this package.
## Discover the API contract

This package is currently maintaining by these authors.
Open <http://localhost:8000/api/_/apidoc> to discover the available API routes and their request and response schemas.

<a href="https://github.com/f3l1x">
<img width="80" height="80" src="https://avatars2.githubusercontent.com/u/538058?v=3&s=80">
</a>
## Develop the repository checkout

-----
Repository contributors can use these Make targets; they are not included in projects installed from the package distribution:

Consider to [support](https://contributte.org/partners.html) **contributte** development team. Also thank you for using this project.
```bash
make qa # coding standard and static analysis
make tests # Nette Tester suite
make cs # coding standard check
make csf # fix coding standard issues
make phpstan # static analysis
make coverage # generate coverage output
```