Code Monkey home page Code Monkey logo

rest-bundle's Introduction

LemonRestBundle

Build Status

This bundle provides REST endpoints for Doctrine entities. It is a highly opinionated, convention driven solution to rapidly deploying a REST API. It relies on the strengths of libraries like JMS Serializer, Will Durands Content Negotiation library and the Doctrine Object Relation Mapper library to make assumptions and drive your REST API off of convention.

If you are looking for an extremely flexible way to build REST APIs this library is not for you, and I suggest you take a look at the fantastic work being done on the Friends of Symfony REST Bundle.

Authors

Changes

Details about changes from version to version are stored in CHANGELOG.md

Documentation

Documentation is stored in the Resources/doc/index.md file in this bundle:

Demo

A demo application is available at https://github.com/stanlemon/rest-demo-app

You can also try it yourself online at http://restdemo-stanlemon.rhcloud.com

Installation

All the installation instructions are located in the documentation.

Reporting an issue or a feature request

Issues and feature requests are tracked in the Github issue tracker.

Contributing

Go for it! Please open a PR against the develop branch and make sure to, at the very least, include a functional test covering your work. Or even better, full functional and unit tests!

rest-bundle's People

Contributors

dependabot-preview[bot] avatar ehibes avatar gromnan avatar hason avatar insekticid avatar jpetitcolas avatar jroussay avatar kix avatar lebaz20 avatar mattjanssen avatar mhor avatar michelpa avatar plpeeters avatar stanlemon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rest-bundle's Issues

Order By

Hello,

I just give up a test on your bundle... and i like it...

I've got one question: can you explain a little bit how request are handled? As i see, it's all handled via the restController right? What about order by?

Thanks!

Add the ability to register entities through semantic configuration

First phase would be just to register individual entities from the configuration into the object registry. Second phase would be to investigate adding directories that could be iterated through to add entities for. It also seems reasonable to add a configuration directive to turn off the compiler pass that scans bundles.

Better naming

Thinking out loud...

Current Proposed
Request\Handler Request\RequestHandler
Object\Criteria Object\Criteria\CriteriaInterface
Object\Criteria\DefaultCriteria Object\Criteria\SimpleCriteria
Object\Envelope Object\Envelope\EnvelopeInterface
Object\Envelope\DefaultEnvelope Object\Envelope\NestedEnvelope
Object\Envelope\Flattened Object\Envelope\FlatEnvelope
Object\Exception\InvalidException Object\Exception\InvalidObjectException
Object\Exception\NotFoundException Object\Exception\ObjectNotFoundException

Would it be better to refer to these as "Resource" instead of "Object"? Principally this is the communication of a object/model/class/blah as a resource.

By convention should something that utilizes a namespace component start with that component in the class name, ie. Lemon\RestBundle\Object\Manager -> Lemon\RestBundle\Object\ObjectManager This seems to be the current convention with a lot of libraries right now.

Add support for JMS Serializer groups in views

Hi,
First your bundle is awesome :).
But I have a question, how I can use JMS Serializer groups ?
I defined some groups like "list" and "details" :

  • list is for api/entity
  • details for api/entity/{id}

For the list group I don't want all the properties of relation, just the id, i.e for a user entity:

[{
    "id": 1,
    "lastname": "Do",
    "firstname": "John",
    "group": 42
},{
    "id": 2,
    "lastname": "Son",
    "firstname": "Thom",
    "group": 21
}]

And for the details group I want all the properties of relation, i.e for a user entity:

{
    "id": 1,
    "lastname": "Do",
    "firstname": "John",
    "group":  {
        "id": 42,
        "name": "anonymous"
    }
}

I tried to use "lemon_rest.event_subscriber" by creating my subscriber, but I feel I can't access to the serializer
Or may be I can try with the "kernel.response" event but it feel to overkill.

I hope my question is clear. I wait your answer

Default to json format for html?

I'm wondering if from a usability stand point it would make sense to render json when the content type is unspecific or 'html', thus meaning that you could navigate end points in the browser pretty easily.

The format "" is not supported for serialization

Hi,
When I try to do a get or a post call I get this error:

"The format "" is not supported for serialization"
I have tried with a simple object with only id and name fields.

I haven't found any related issues/fix

"jms_serializer.json_serialization_visitor.options" not found

Hi, i´ve just followed the Install instructions and after runing symfony it throw the following exception

ParameterNotFoundException in ParameterBag.php line 106:
You have requested a non-existent parameter "jms_serializer.json_serialization_visitor.options".

many-to-many update

I´ve following issue occuring, whenever i make a PUT request by removing a Many-To-Many Entity the complete stack gets deleted.

Owning Side

<?xml version="1.0" encoding="UTF-8" ?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
        http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="AppBundle\Entity\User" table="user">
        <id name="id" type="integer">
            <generator strategy="AUTO" />
        </id>
        <field name="name" type="string" length="100" />
        <field name="email" type="string" />

        <many-to-many field="roles" inversed-by="users" target-entity="AppBundle\Entity\Role">           
            <join-table name="users_roles">
                <join-columns>
                    <join-column name="user_id" referenced-column-name="id"/>
                </join-columns>
                <inverse-join-columns>
                    <join-column name="role_id" referenced-column-name="id"/>
                </inverse-join-columns>
            </join-table>
        </many-to-many>

    </entity>
</doctrine-mapping>

Role

<?xml version="1.0" encoding="UTF-8" ?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
        http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="AppBundle\Entity\Role" table="role">
        <id name="id" type="integer">
            <generator strategy="AUTO" />
        </id>
        <field name="name" type="string" length="100" />
        <many-to-many field="users" target-entity="AppBundle\Entity\User" mapped-by="roles">            </many-to-many>
    </entity>
</doctrine-mapping>

Now the Object before:

{
  'user': 'blablalbla...',
  'roles'; [
 { role: 'blablablal'...}
]
}

I make an PUT request with the follwing:

{
  'user': 'blablalbla...',
  'roles'; []
}

And guess what happens? The not only does the joinTable get empty as it should be, but also the Role Entity gets removed from the Repository.

PATCH Support

I am still considering the best way to implement this, but at the moment I am leaning towards using a partial object instead of something like JSON Patch (https://tools.ietf.org/html/rfc6902) due to it's lack of support in the wild currently.

I think this can be easily added by taking advantage of the DoctrineObjectConstructor in JMS Serializer. However, the bundle does not make it easy to create a second instance of the serializer with a different constructor, as I need to keep using the standard object constructor with the other request types. I will probably hack something ugly together as a proof of concept and then clean it up in a way that isn't so distasteful thereafter.

Make the default envelope flattened

This would be a change to the out of the box configuration of LemonRestBundle. I'm noticing most js libraries seem to expect the flattened response and thus I'm leaning towards making this the default behavior.

Add support for custom/flexible envelopes

Ember.Data for example nests responses in a property labeled for the resources, for example:

{
  "post": {
     "id": 1
   }
}

Likewise Restangular and tools like ng-admin wants collections that are not nested, something like:

[{}, {}, {}]

Add an envelope factory with an export method and define two different envelope types, an individual object and a collection of objects, and allow this to alter the structure that gets sent to JMS Serializer for serialization. Default behavior should be what's currently done. This would most likely be manipulated through the semantic config being added in #2

Configure the default LIMIT

The default number of items per page is currently hardcoded in the DefaultCriteria.
It would be nice if this could be in the bundle configuration.

Example:

lemon_rest:
    defaults:
        limit: 500

Add nested collection (>2nd level)

Hi,

I would like to POST an entity with a nested collection in a nested collection.
First collection is saved, but second not.
I wrote a test in pull request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.