Mirv / basicb

Basic is as basic does...
https://github.com/Mirv/basicb/wiki
0 stars 0 forks source link

api v1 #119

Open Mirv opened 6 years ago

Mirv commented 6 years ago

https://blog.kollegorna.se/build-an-api-in-your-rails-app-now-c29b99a55d7b

api controllers

router

serializers

show

index

got all my controllers & routes set for new api on top of my normal basicB rails app in like 30 mins ... need to finish writing serializations for it though

Mirv commented 6 years ago

Note: ... suggested an initializer for api

If we now request a single user it will also render all microposts, followers and followings (users that the user follows). Usually we don’t want that but instead we probably want AMS to render only the ids. In an initializer add:

ActiveModel::Serializer.setup do |config|
  config.embed = :ids
end
Mirv commented 6 years ago

Tip: Exceptions in Ruby are quite slow. A faster way is to request the user from the db using findby and render 404 if findby returned a nil.

Mirv commented 6 years ago

inserted base serializer class from his github ... https://github.com/vasilakisfil/rails5_api_tutorial/blob/master/app/serializers/api/v1/base_serializer.rb

Mirv commented 6 years ago

Need to work out different between gem 'active_model_serializers' & getting it from github directly.

Index might have been working using the direct github DL ... then the bundle had issues installing - I think i got it working using gem install active_model_serializers ... later it's not recognizing the namespace.

https://stackoverflow.com/questions/43254528/nameerror-uninitialized-constant-activemodelserializersxml-when-declaring-a

gem install active_model_serializers # failed to fix