• Stars
    star
    336
  • Rank 125,564 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 12 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple silex skeleton for writing scalable rest api

Silex Simple REST

Latest Stable Version Total Downloads Build Status

A simple silex skeleton application for writing RESTful API. Developed and maintained by Alessandro Arnodo.

This project wants to be a starting point to writing scalable and maintainable REST api with Silex PHP micro-framework

Continuous Integration is provided by Travis-CI.

How do I run it?

After download the last release, from the root folder of the project, run the following commands to install the php dependencies, import some data, and run a local php server.

You need at least php 5.5.9* with SQLite extension enabled and Composer

composer install 
sqlite3 app.db < resources/sql/schema.sql
php -S 0:9001 -t web/

You can install the project also as a composer project

	composer create-project vesparny/silex-simple-rest

Your api is now available at http://localhost:9001/api/v1.

Run tests

Some tests were written, and all CRUD operations are fully tested :)

From the root folder run the following command to run tests.

vendor/bin/phpunit 

What you will get

The api will respond to

GET  ->   http://localhost:9001/api/v1/notes
GET  ->   http://localhost:9001/api/v1/notes/{id}
POST ->   http://localhost:9001/api/v1/notes
PUT ->   http://localhost:9001/api/v1/notes/{id}
DELETE -> http://localhost:9001/api/v1/notes/{id}

Your request should have 'Content-Type: application/json' header. Your api is CORS compliant out of the box, so it's capable of cross-domain communication.

Try with curl:

#GET (collection)
curl http://localhost:9001/api/v1/notes -H 'Content-Type: application/json' -w "\n"

#GET (single item with id 1)
curl http://localhost:9001/api/v1/notes/1 -H 'Content-Type: application/json' -w "\n"

#POST (insert)
curl -X POST http://localhost:9001/api/v1/notes -d '{"note":"Hello World!"}' -H 'Content-Type: application/json' -w "\n"

#PUT (update)
curl -X PUT http://localhost:9001/api/v1/notes/1 -d '{"note":"Uhauuuuuuu!"}' -H 'Content-Type: application/json' -w "\n"

#DELETE
curl -X DELETE http://localhost:9001/api/v1/notes/1 -H 'Content-Type: application/json' -w "\n"

What's under the hood

Take a look at the source code, it's self explanatory :) More documentation and info about the code will be available soon.

Under the resources folder you can find a .htaccess file to put the api in production.

Contributing

Fell free to contribute, fork, pull request, hack. Thanks!

Author

License

see LICENSE file.

More Repositories

1

fair-analytics

๐Ÿ“Š An analytics server that doesn't undermine user's privacy
JavaScript
748
star
2

morpheus

The next generation web publishing platform built with React.js
JavaScript
673
star
3

angular-kickstart

angular-kickstart - speed up your AngularJS development and testing with a great gulpjs build system.
JavaScript
552
star
4

statty

A tiny and unobtrusive state management library for React and Preact apps
JavaScript
512
star
5

marky

A markdown editor built with Electron and React
JavaScript
355
star
6

codeigniter-html5boilerplate-twitter-bootstrap

DEPRECATED
PHP
195
star
7

react-kickstart

just another react + webpack boilerplate
JavaScript
186
star
8

markeye

A previewer for Markdown files
JavaScript
77
star
9

cimongo-codeigniter-mongodb-library

DEPRECATED
PHP
74
star
10

angular-fancy-modal

angular-fancy-modal - the definitive modal/popup/dialog solution for AngularJS.
JavaScript
62
star
11

brcast

Tiny data broadcaster with 0 dependencies
JavaScript
47
star
12

flux-immutable-example

A trivial example app with flux, flummox, react-router, webpack and Immutable.js
CSS
43
star
13

borgjs

๐Ÿ“ฆ A tiny wrapper for BorgBackup to automate your backup workflow
JavaScript
31
star
14

fair-analytics-client-api

The Fair Analytics client API
JavaScript
20
star
15

angularjs-playground

A starting point for being up and running in minutes with angularJS.
JavaScript
16
star
16

rxhr

Tiny Observable based HTTP client for browsers
JavaScript
15
star
17

todoo

Todos for introverts
JavaScript
14
star
18

preact-glam

A tiny glamorous version for preact
JavaScript
11
star
19

widget

CSS
3
star
20

is-shallow-equal

shallowly compares two objects
JavaScript
3
star
21

datbox

peer-to-peer file sharing in your browser
JavaScript
1
star
22

site

my website
HTML
1
star