weew/http-blueprint 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

weew/http-blueprint

Composer 安装命令:

composer require weew/http-blueprint

包简介

Very basic blueprint server for API prototyping.

README 文档

README

Build Status Code Quality Test Coverage Dependencies Version Licence

Table of contents

Installation

composer require weew/http-blueprint

Introduction

This little package allows you to easily spin up a server, maybe during your unit tests. It consists of two parts, the server and the proxy. The server is responsible for starting and stopping of, big surprise, the http server. The proxy is basically responsible for grabbing all of the registered routes, figuring out which one should be called and returning an http response.

This package was mainly built for testing of the http layer and the http client where I could not simply mock the endpoints, but had instead to actually test the whole http communication and the resulting requests and responses. But at the end I think this is a really useful package and might be used elsewhere as well.

Creating a blueprint

Create a file that will be used as your blueprint. Register your routes in there. Let the proxy to the rest.

// file: blueprint.php

// create a proxy
$proxy = new BlueprintProxy();

// register all of your routes
$proxy->getRouter()
    ->get('/', 'hello world')
    ->get('about', new HttpResponse(HttpStatusCode::OK, 'foo'))
    ->post('post', function() {
        return 'hello world';
    })
    ->put('users/{id}', function(IHttpRequest $request, array $parameters) {
        return new HttpResponse(HttpStatusCode::OK, $parameters['id']);
    });

// send a response
$proxy->sendResponse();

Starting and stopping the server

It is very easy. Just pass in the hostname, your desired port, and the path to the blueprint file you've created.

$server = new BlueprintServer('localhost', 9000, '/path/to/blueprint.php');
$server->start();

When you're done, simply stop the server.

$server->stop();

Related projects

  • HTTP Layer: offers response and request objects, handles cookies, headers and much more.
  • HTTP Server: allows you to start an http server in a directory of your choice.
  • HTTP Client: allows you to send HttpRequest and to receive HttpResponse objects.
  • Router: allows you to create complex routes and map them to a response.

统计信息

  • 总下载量: 50
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固